最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - NodeJS - Spawn function - Stack Overflow

programmeradmin4浏览0评论

I'm working with nodejs and the child process module to execute mands on my platform. To do that, I use the spawn function.

Here's my code:

var spawn_execution = executor.spawn(mand, args);

spawn_execution.stdout.on('data', function (data) {
    console.log('stdout: ' + data);
});

spawn_execution.stderr.on('data', function (data) {
    console.log('stderr: ' + data);
});

Nothing fancy. So I tried a couple of mands that worked like

executor.spawn('C:/path/to/ffmpeg.exe', [...]);

But when I try to use a native windows mand, it does not work. For instance, I tried:

executor.spawn('del', ['C:\\my\\file\\to\\delete']);

When executing this, I've got a ENOENT error which means that the file is not found. So I did another thing:

executor.spawn('C:/my/script-delete.exe', ['C:\\my\\file\\to\\delete']);

This script-delete.exe just contains:

del %1

So why does the spawn function need to have a script file? Why does it not work with native windows mand? Do you know a way to make it work with a native mand?

Thank you!

I'm working with nodejs and the child process module to execute mands on my platform. To do that, I use the spawn function.

Here's my code:

var spawn_execution = executor.spawn(mand, args);

spawn_execution.stdout.on('data', function (data) {
    console.log('stdout: ' + data);
});

spawn_execution.stderr.on('data', function (data) {
    console.log('stderr: ' + data);
});

Nothing fancy. So I tried a couple of mands that worked like

executor.spawn('C:/path/to/ffmpeg.exe', [...]);

But when I try to use a native windows mand, it does not work. For instance, I tried:

executor.spawn('del', ['C:\\my\\file\\to\\delete']);

When executing this, I've got a ENOENT error which means that the file is not found. So I did another thing:

executor.spawn('C:/my/script-delete.exe', ['C:\\my\\file\\to\\delete']);

This script-delete.exe just contains:

del %1

So why does the spawn function need to have a script file? Why does it not work with native windows mand? Do you know a way to make it work with a native mand?

Thank you!

Share Improve this question asked Oct 10, 2013 at 8:33 user734613user734613
Add a ment  | 

1 Answer 1

Reset to default 9

It doesn't work as the internal mands can't be found from executor.spawn only cmd.exe knows them.

So it works from a batch file or when you use something like

executor.spawn('cmd.exe', ['/C', 'del', 'C:\\my\\file\\to\\delete']);
发布评论

评论列表(0)

  1. 暂无评论