![](/img/trans.png)
[英]node child_process.spawn not working with spaces in path on windows
[英]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'
}
這僅在特殊配置中發生:
another.js
, npm
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.