节点child_process:嵌套批处理文件

时间:2016-08-12 18:17:27

标签: javascript node.js windows batch-file child-process

我正在尝试通过节点spawn()执行批处理脚本,如下所示:

const spawn = require('child_process').spawn;
const script = require.resolve('./script_1.bat');
const bat = spawn(script);

/* program runs properly (for the most part) */
bat.stderr.on('data', (data) => {
    console.log('stdErr: ' + data);
});

bat.on('exit', (code) => {
    console.log('Child exited with code' + code);
});

问题是script_1.bat在同一目录中对call有一个script_2.bat命令:

`call script_2.bat`

当我在命令行中执行script_1.bat时,它工作正常。但是,当我从节点运行script_1.bat时,我在控制台中看到了这一点:

stdErr: 'script_2.bat' is not recognized as an internal or external command, operable program or batch file.

我已尽力挖掘节点子进程文档,但我找不到为什么会发生这种情况的探索。有没有办法将嵌套的批处理文件传递给spawn()方法一些如何?

感谢您的时间。

0 个答案:

没有答案