I am trying to spawn a command in node with ipc option via child_process spawn.
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:
- on windows
- with 'ipc' option
- spawned command is something in js
will fail:another.js,npm
will not fail:node
There is a closed issue that's not much useful.
I need the shell: true for cross-platform compatibility according to this article.
Also this issue seems related but I am not smarter after reading it.
node v12.18.3
Thanks for help.