node.js - Change from child process exec to spawn dont work -
i use child process exec , need switch child process spawn
this working me.
var child = child_process.exec("npm install express --save" options, function (error, stdout, stderr) { ..... });
when switch spawn doesnt work got error
var child = child_process.spawn("npm install express --save" options); error: spawn npm enoent @ exports._errnoexception (util.js:746:11) @ process.childprocess._handle.onexit (child_process.js:1053:32) @ child_process.js:1144:20
i try var child = child_process.spawn("npm", ["install express --save"], options)
;
and doesnt work me, can issue?
i guess on windows environment.
so, have enter terminal , use commands want.
we see in node.js docs child_process.exec() method has spec in options default according operating system.
shell string shell execute command (default: '/bin/sh' on unix, 'cmd.exe' on windows, shell should understand -c switch on unix or /s /c on windows. on windows, command line parsing should compatible cmd.exe.)
so when using spawn, things changing.
var child = child_process.spawn("cmd",["/c","npm install express --save"], options);
the above code block, starts new instance of windows command interpreter(cmd)
, carries out command specified string , terminates(/c)
, our specific command npm install express --save
works on windows command interpreter.windows cmd commands references
Comments
Post a Comment