Retrieve bash error from NodeJS child_process.spawn
Asked Answered
N

1

1

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?

Neoplasty answered 14/4, 2015 at 5:7 Comment(0)
C
1

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
Cuzco answered 14/4, 2015 at 8:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.