paulcpederson
paulcpederson

Reputation: 1447

Retrieve bash error from NodeJS child_process.spawn

When I execute the (made up and ridiculous) command banana from bash I get the following error:

bash: banana: command not found

But if I execute banana in a child_process.spawn in Node.js, I get the error:

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

Is there any way to get the text of the original bash error from Node.JS?

Upvotes: 1

Views: 812

Answers (1)

James Thomas
James Thomas

Reputation: 4339

Attaching to the 'error' event emitter for the child_process.spawn will give you the following message:

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

Error: spawn bananas ENOENT

Upvotes: 1

Related Questions