我正在尝试通过节点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()
方法一些如何?
感谢您的时间。