繁体   English   中英

带有ipc的windows上的节点child_process.spawn错误文件描述符

[英]Node child_process.spawn bad file descriptor on windows with ipc

我正在尝试通过 child_process spawn 在节点中使用 ipc 选项生成命令。

我叫什么:

const {spawn} = require('child_process');
const cmd = spawn('npm', ['-v'], {
    shell: true,
    stdio: ['inherit', 'inherit', 'inherit', 'ipc']
});
cmd.on('message', (msg) => console.log(msg));

我得到什么:

child_process.js:122
  p.open(fd);

Error: EBADF: bad file descriptor, uv_pipe_open

Child (child_process.js:122:5)
    at setupChildProcessIpcChannel (internal/bootstrap/pre_execution.js:329:30)
    at prepareMainThreadExecution (internal/bootstrap/pre_execution.js:54:3)
    at internal/main/run_main_module.js:7:1 {
  errno: -4083,
  code: 'EBADF',
  syscall: 'uv_pipe_open'
}

这仅在特殊配置中发生:

  1. 在 windows
  2. 带有“ipc”选项
  3. 生成的命令是 js 中的东西
    将失败: another.jsnpm
    不会失败: node

有一个没有多大用处的已关闭问题

根据本文,我需要shell: true以实现跨平台兼容性。

这个问题也似乎相关,但读完后我并不聪明。

节点 v12.18.3

感谢帮助。

you cannot use 'ipc' with npm, because npm "binary" is a shell script, not a node process (see https://github.com/npm/cli/tree/latest/bin )

文件

不支持以除 process.send() 以外的任何方式访问 IPC 通道 fd 或将 IPC 通道与不是 Node.js 实例的子进程一起使用。

对于another.js ,使用fork (将始终有效)或 `spawn('node', 'another.js') 如果您不使用节点 shim(如 nodist),这应该可以工作

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM