child_process: fork() with shell is impossible?
- Version: from v4. x up to v9.0
- Platform: Windows 7 x64
- Subsystem: child_process
Currently, the doc says nothing if fork() is executed with shell, also no shell option is mentioned. However, fork() is based upon spawn() and almost all the options are transferred as is. So, without shell option we have the default spawn() behavior (without shell):
if (!process.argv[2]) { require('child_process').fork(__filename, ['%temp%'], { }); } else { console.log(process.argv[2]); }
However, if shell option is set to true, fork() becomes broken in at least two ways:
- If a path to the executable has spaces, we have this error:
if (!process.argv[2]) { require('child_process').fork(__filename, ['%temp%'], { shell: true }); } else { console.log(process.argv[2]); }
>node test.js 'C:\Program' is not recognized as an internal or external command, operable program or batch file.
- If a path to the executable has no spaces, we have this error:
>node.8.1.3.exe test.js child_process.js:106 p.open(fd); ^ Error: EBADF: bad file descriptor, uv_pipe_open at Object.exports._forkChild (child_process.js:106:5) at Object.setupChannel (internal/process.js:247:8) at startup (bootstrap_node.js:53:16) at bootstrap_node.js:575:3
So there are some questions:
- Should we document
fork()and shell interaction (andshelloption) and fix these issues? - If not, should we strip
shelloption before spawning (and maybe somehow document this)?