Search code examples
javascriptnode.jsexecspawn

node require('child_process').spawn throws ENOENT


I'm using the node child process to spawn a shell and run a binary inside of it. I'm referencing the binary something like below but i get ENOENT error.

var spawn  = require('child_process').spawn;
    binary = spawn('PATH_TO_BINARY') //i refer it like   app.get('Config').ROOT_PATH + '/folderName/Binary -c' + app.get('Config').ROOT_PATH + '/configfolderName/BinaryConfig.cfg'

Then i have binary.stdout.on, binary.stderr.on listeners but when i run the app i get this error uncaughtException: spawn "binary path" ENOENT

On the other hand if i use "exec" it works, any idea why it's failing while using spawn and running while using exec.

I cannot use exec in this case because i'm dealing with event streams here so it looks like the ideal thing for streams is spawn and not exec.Got that from here http://www.hacksparrow.com/difference-between-spawn-and-exec-of-node-js-child_process.html


Solution

  • Here's how this can be resolved, https://github.com/nodejs/help/issues/163

    Hope it might help someone.