镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

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

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)?

Activity

  1. cjihrig commented on Jul 1, 2017

    @cjihrig
    Contributor

    FWIW, I can't reproduce with master on macOS. Perhaps this is Windows specific.

  2. added
    windowsIssues and PRs related to the Windows platform.
    on Jul 1, 2017
  3. bnoordhuis commented on Aug 3, 2017

    @bnoordhuis
    Member

    If not, should we strip shell option before spawning (and maybe somehow document this)?

    Let's do this; fork() + shell doesn't make sense. I've added a good-first-contribution label.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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