gpt4 book ai didi

node.js - Node child_process.spawn 在带有 ipc 的 windows 上的坏文件描述符

转载 作者:行者123 更新时间:2023-12-04 17:26:08 25 4
gpt4 key购买 nike

我试图通过 child_process spawn 在带有 ipc 选项的 Node 中生成一个命令。
我称之为:

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'
}
这仅在特殊配置中发生:
  • 在 window 上
  • 带有“ipc”选项
  • spawned 命令是 js 中的东西
    会失败:another.js , npm不会失败:node

  • 有一个 closed issue那没有多大用处。
    我需要 shell: true根据此 article 实现跨平台兼容性.
    还有这个 issue似乎相关,但阅读后我并不聪明。
    Node v12.18.3
    感谢帮助。

    最佳答案

    你不能在 npm 中使用 'ipc',因为 npm “binary” 是一个 shell 脚本,而不是一个 Node 进程(见 https://github.com/npm/cli/tree/latest/bin)
    documentation

    Accessing the IPC channel fd in any way other than process.send() or using the IPC channel with a child process that is not a Node.js instance is not supported.


    another.js , 要么使用 fork (将始终有效)或 `spawn('node', 'another.js') 如果您不使用 Node 垫片(如 nodist),它应该可以工作

    关于node.js - Node child_process.spawn 在带有 ipc 的 windows 上的坏文件描述符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63303200/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com