Skip to content

child_process.spawn adds flags that might cause non-native shells to fail on windows #19947

Description

@idanpa
  • Version: 8.11.1
  • Platform: Windows 10 64 bit
  • Subsystem: child_process

On Windows, when child_process.spawn is given the optional shell parameter (#4598) it makes an assumption that the shell would understand the /c /s flags (cmd.exe or powershell).
This limits the option to use bash (using WSL) on windows.
Can by bypassed by:

args = ["\"", cmd].concat(args, "\"");
currentSync = child.spawn("bash -c", args, {stdio: 'pipe', shell: "cmd.exe"});

But would be nice to have a better solution.

Thanks,
Idan

Activity

  1. vsemozhetbyt commented on Apr 11, 2018

    @vsemozhetbyt
    Contributor
  2. added
    child_processIssues and PRs related to the child_process subsystem.
    windowsIssues and PRs related to the Windows platform.
    wslIssues and PRs related to the Windows Subsystem for Linux.
    on Apr 11, 2018
  3. bnoordhuis commented on Apr 11, 2018

    @bnoordhuis
    Member

    Yep, and it doesn't seem like an unreasonable restriction to me. I don't really see how we could improve it either.

  4. idanpa commented on Apr 11, 2018

    @idanpa
    Author

    @bnoordhuis what do you say about these options:

    1. Having shellOptions arg with default value '/d /s /c' on windows and '-sc' on unix
    2. Skip adding the options if shell string already contains flags (having either " -" or " /"
    3. Having 2 different optional args - shshell and ntshell that gets the right options accordingly (without checking the platform)
  5. bnoordhuis commented on Apr 11, 2018

    @bnoordhuis
    Member

    (1) and (3) are fixing a problem that isn't really a problem (don't use .shell, spawn the shell directly) and (2) is the kind of heuristic that can have false positives (e.g. / is also a path separator.)

    I mean, yes, there are ways to solve your issue with more API options but the extra complexity doesn't seem worth it.

  6. bnoordhuis commented on Apr 23, 2018

    @bnoordhuis
    Member

    I'll close this out. It's been two weeks and no one spoke out in favor of making changes.

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.windowsIssues and PRs related to the Windows platform.wslIssues and PRs related to the Windows Subsystem for Linux.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions