这将引发 ENOENT 错误:
const cmd = 'bash my/path/to/script.sh';
const process = spawn(cmd);
process.on('exit', (code) => {
console.log("Child exited");
});
虽然这不会按预期执行脚本:
const cmd = 'bash my/path/to/script.sh';
exec(cmd, function(err, stdout, stderr) {
console.log(stdout);
});
现在,我想从中spawn()获取数据流并使其正常工作。这种行为可能来自哪里的任何建议?
我检查了一下pwd,两者的当前工作目录相同。