Javascript NodeJS-childprocessexecfile-Uncaught错误:spawn enoint
我正在尝试通过node.js()将unix可执行文件作为外部应用程序运行 程序Javascript NodeJS-childprocessexecfile-Uncaught错误:spawn enoint,javascript,node.js,exec,child-process,spawn,Javascript,Node.js,Exec,Child Process,Spawn,我正在尝试通过node.js()将unix可执行文件作为外部应用程序运行 程序标识符应使用参数--help执行,而不是在以下情况下失败: console.log(execPath)在我的节点项目中打印正确的标识符 这实际上返回根节点项目的目录,并以代码0退出: var sys = require('sys'), spawn = require('child_process').spawn, ls = spawn('ls', ['-l']); ls.stdout.on
标识符
应使用参数--help
执行,而不是在以下情况下失败:
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
- 如何在NodeJS中正确运行带有args的可执行文件?
- 感谢@innis指出参数应该是
:
为什么您的execPath在options参数的数组中?医生们说,他们正在等待一个反对者。谢谢你的提示@innis,我应该在阅读我可以帮助的文档时更加彻底。
Uncaught Error: spawn identifiers ENOENT
at Process.ChildProcess._handle.onexit (internal/child_process.js:264)
at onErrorNT (internal/child_process.js:456)
at processTicksAndRejections (internal/process/task_queues.js:80)
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);
});
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);
});