使用子进程NodeJS运行exe文件 [英] Run exe file with Child Process NodeJS
本文介绍了使用子进程NodeJS运行exe文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用nodejs打开谷歌浏览器,但出现此错误(我使用execFile和spawn),
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)
推荐答案
每个命令都在一个单独的shell,因此第一个cd仅影响该shell进程,然后终止。如果要在特定目录中运行git,只需让Node为您设置路径:
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(当前工作目录)是可用于exec的众多选项之一。请参阅链接
cwd (current working directory) is one of many options available for exec.refer to link
这篇关于使用子进程NodeJS运行exe文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文