从NodeJS child_process.spawn中检索bash错误

时间:2015-04-14 05:07:43

标签: node.js bash child-process

当我从bash执行(编造和荒谬)命令banana时,我收到以下错误:

bash: banana: command not found

但是如果我在Node.js中的banana中执行child_process.spawn,我会收到错误:

net.js:624
    throw new TypeError('invalid data');
          ^
TypeError: invalid data
    at WriteStream.Socket.write (net.js:624:11)
    at ChildProcess.<anonymous> 
    at ChildProcess.emit (events.js:107:17)
    at Process.ChildProcess._handle.onexit (child_process.js:1065:12)
    at child_process.js:1137:20
    at process._tickCallback (node.js:355:11)
    at Function.Module.runMain (module.js:503:11)
    at startup (node.js:129:16)
    at node.js:814:3

有没有办法从Node.JS获取原始bash错误的文本?

1 个答案:

答案 0 :(得分:1)

附加错误&#39; child_process.spawn的事件发射器将为您提供以下消息:

child_process_instance.on('error', function (error) {
    console.log(error);
});

Error: spawn bananas ENOENT