2017-09-27 97 views
1

我想使用nodejs在命令提示符下运行命令。
基于https://dzone.com/articles/understanding-execfile-spawn-exec-and-fork-in-node,我使用exec vs execFile nodeJs

child_process.execFile('protractor', ['./src/convertedJs/tempProtractorconfig.js'], (err, stdout, stderr) => {} 

上面的代码抛出一个ENOENT错误。
但是当我运行

child_process.exec('protractor ./src/convertedJs/tempProtractorconfig.js', (err,stdout,stderr) => {}` 

一切工作正常。
有人可以解释发生了什么?

在v9.5.0的NodeJS
+0

你确定你是从同一目录中运行他们两个? –

+0

yepss ..我在同一个目录中运行 –

回答

0

,所述exec被定义为在以下文件LIB/child_process.js

exports.exec = function(command /*, options, callback*/) { 
var opts = normalizeExecArgs.apply(null, arguments); 
return exports.execFile(opts.file, opts.options, opts.callback); 

};

这意味着,最后exec电话execFile到EXCUTE您的命令,所以你的情况很奇怪,execFile失败,但exec不是