Skip to content

child_process: fork() with shell is impossible? #13983

Closed
@vsemozhetbyt

Description

@vsemozhetbyt
  • 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]);
}
%temp%

However, if shell option is set to true, fork() becomes broken in at least two ways:

  1. 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.
  1. 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:

  1. Should we document fork() and shell interaction (and shell option) and fix these issues?
  2. If not, should we strip shell option before spawning (and maybe somehow document this)?

Metadata

Metadata

Assignees

No one assigned

    Labels

    child_processIssues and PRs related to the child_process subsystem.good first issueIssues that are suitable for first-time contributors.windowsIssues and PRs related to the Windows platform.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions