Run exe file with Child Process NodeJS

六月ゝ 毕业季﹏ 提交于 2019-12-10 17:05:47

问题


I want to open google chrome with nodejs, but I get this error (I used execFile and spawn),

code

var execFile = require('child_process').execFile,
spawn = require('child_process').spawn,

spawn('C\\Program Files\\Google\\Chrome\\Application\\chrome.exe', function (error, stdout, stderr) {
   if (error !== null) { console.log('exec error: ' + error); }
});

events.js:72
    throw er; // Unhandled 'error' event
          ^
Error: spawn ENOENT
at errnoException (child_process.js:998:11)
at Process.ChildProcess._handle.onexit (child_process.js:789:34)

回答1:


Each command is executed in a separate shell, so the first cd only affects that shell process which then terminates. If you want to run git in a particular directory, just have Node set the path for you:

exec('git status', {cwd: '/home/ubuntu/distro'}, /* ... */);

cwd (current working directory) is one of many options available for exec.refer to link



来源:https://stackoverflow.com/questions/23764429/run-exe-file-with-child-process-nodejs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!