[英]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:这仅在特殊配置中发生:
another.js
, npm
将失败: another.js
, npm
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.