javascript - NodeJS - Spawn function - Stack Overflow

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

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']);

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1743858802a4519329.html

相关推荐

  • javascript - NodeJS - Spawn function - Stack Overflow

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

    1天前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信