我试图通过node.js:(参考文献)作为外部应用程序运行unix可执行文件
const execFile = require('child_process').execFile;
const executable = execFile('identifiers', ['--help'], [execPath], (error, stdout, stderr) => {
if (error) {
console.error('stderr', stderr);
throw error;
}
console.log('stdout', stdout);
});程序identifiers应该使用参数--help执行,而不是在以下情况下失败:
未知错误:在Process.ChildProcess._handle.onexit ( onErrorNT /child_process.js:264)、processTicksAndRejections (内部/进程/任务_Quees.js:80)处生成标识符ENOENT
identifiers在我的节点项目中打印正确的console.log(execPath)执行路径。
这实际上返回根节点项目的目录,并使用代码0退出:
var sys = require('sys'),
spawn = require('child_process').spawn,
ls = spawn('ls', ['-l']);
ls.stdout.on('data', function (data) {
console.log('stdout: ' + data);
});
ls.stderr.on('data', function (data) {
console.log('stderr: ' + data);
});
ls.on('exit', function (code) {
console.log('exit code ' + code);
});execFile 会抛出错误?发布于 2020-06-04 09:56:57
感谢@innis指出该参数应该是<Object>
const execFile = require('child_process').execFile;
const executable = execFile('./identifiers', ['--id', '1'], {'cwd': execPath}, (error, stdout, stderr) => {
if (error) {
console.error('stderr', stderr);
throw error;
}
console.log('stdout', stdout);
});https://stackoverflow.com/questions/62184038
复制相似问题