首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NodeJS - ChildProcess execFile -未明错误:产卵

NodeJS - ChildProcess execFile -未明错误:产卵
EN

Stack Overflow用户
提问于 2020-06-03 22:50:48
回答 1查看 1.3K关注 0票数 2

我试图通过node.js:(参考文献)作为外部应用程序运行unix可执行文件

代码语言:javascript
复制
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退出:

代码语言:javascript
复制
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适当地运行可执行文件
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-06-04 09:56:57

感谢@innis指出该参数应该是<Object>

代码语言:javascript
复制
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);
});
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62184038

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档