简体   繁体   English

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

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

I am trying to spawn a command in node with ipc option via child_process spawn.我正在尝试通过 child_process spawn 在节点中使用 ipc 选项生成命令。

What I call:我叫什么:

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

What I get:我得到什么:

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'
}

This happnes only in special configuration:这仅在特殊配置中发生:

  1. on windows在 windows
  2. with 'ipc' option带有“ipc”选项
  3. spawned command is something in js生成的命令是 js 中的东西
    will fail: another.js , npm将失败: another.jsnpm
    will not fail: node不会失败: node

There is a closed issue that's not much useful.有一个没有多大用处的已关闭问题

I need the shell: true for cross-platform compatibility according to this article .根据本文,我需要shell: true以实现跨平台兼容性。

Also this issue seems related but I am not smarter after reading it.这个问题也似乎相关,但读完后我并不聪明。

node v12.18.3节点 v12.18.3

Thanks for help.感谢帮助。

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 ) 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 )

documentation says 文件

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

for another.js , either use fork (will always work) or `spawn('node', 'another.js') which should work if you're not using a node shim (like nodist)对于another.js ,使用fork (将始终有效)或 `spawn('node', 'another.js') 如果您不使用节点 shim(如 nodist),这应该可以工作

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

相关问题 node child_process.spawn不使用windows上路径中的空格 - node child_process.spawn not working with spaces in path on windows 节点child_process.spawn多个命令 - Node child_process.spawn multiple commands 如何在Windows上正确使用node.js child_process.spawn()重定向? - How to correctly use node.js child_process.spawn() redirection on Windows? 如何在Ubuntu中作为命令或服务运行可执行文件(使用Node.js child_process.spawn())? - How to run executable file in Ubuntu as a command or service (with Node.js child_process.spawn())? 使用child_process.spawn将execArgs添加到Node可执行文件 - Adding execArgs to Node executable using child_process.spawn 节点:如何从child_process.spawn()流式传输STDERR内容? - Node: How to stream STDERR content from child_process.spawn()? Node.js:捕获`child_process.spawn`的STDOUT - Node.js: Capture STDOUT of `child_process.spawn` 如何使用Node的child_process.spawn将文件作为输入? - How do you use a file as input with Node's child_process.spawn? node.js child_process.spawn no stdout除非'inherit' - node.js child_process.spawn no stdout unless 'inherit' 在Windows上找不到node.js child_process.spawn()的github ssh公钥,但在child_process.exec()上可见 - github ssh public key not found with node.js child_process.spawn() on windows, but visible on child_process.exec()
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM