GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Feature request:child_process.exec for powershell · Issue #21905 · nodejs/node

Feature request:child_process.exec for powershell #21905

New issue
Copy link
New issue
Copy link
Closed
Closed
Feature request:child_process.exec for powershell#21905
Copy link
Labels
child_processIssues and PRs related to the child_process subsystem.feature requestIssues requesting new Node.js features.

Description

@tkamenoko
tkamenoko
opened on Jul 20, 2018
Issue body actions
  • Version:v10.7.0
  • Platform:Windows 10 64bit
  • Subsystem:child_process

On Windows, child_process.exec (or other methods) supports only cmd.exe as the shell, so running the following shows error messages.

const ChildProcess = require("child_process")

// trying to use powershell core(pwsh).
ChildProcess.exec("echo foo", { shell: "pwsh" }, (error, stdout, stderr) => {
    if (error) {
        console.error("exec error: ", error);
        return;
    }
    console.log("stdout: ", stdout);
    console.log("stderr: ", stderr);
})

result:

exec error:  { Error: Command failed: echo foo
The argument '/d' is not recognized as the name of a script file. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

    at ChildProcess.exithandler (child_process.js:291:12)
    at ChildProcess.emit (events.js:182:13)
    at maybeClose (internal/child_process.js:961:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:248:5) killed: false, code: 64, signal: null, cmd: 'echo foo' }

However, there are alternate shells like powershell, git-bash, etc. So I suggest to fix the behavior.

I suppose the cause is this code(a part of child_process.normalizeSpawnArguments):

node/lib/child_process.js

Lines 469 to 479 in c3f8dd6

if (options.shell) {
const command = [file].concat(args).join(' ');
if (process.platform === 'win32') {
if (typeof options.shell === 'string')
file = options.shell;
else
file = process.env.comspec || 'cmd.exe';
args = ['/d', '/s', '/c', `"${command}"`];
options.windowsVerbatimArguments = true;
} else {

On Windows, it sets /d /s /c for args even if options.shell!=="cmd.exe". Powershell can receive -c option like unix shells, so /d /s /c should be used for only cmd.exe.

Reacted by Marc, Pablo Moleri, Daniel Fahlke and Cédric Belin

Activity

  1. gireeshpunathil commented on Jul 20, 2018

    @gireeshpunathil
    gireeshpunathil
    on Jul 20, 2018
    Member
    More actions

    The current behvior is well understood and backed up by documentation:

    The shell should understand the -c switch on UNIX or /d /s /c on Windows. On Windows, command line parsing should be compatible with 'cmd.exe'.

    However, I see it is reasonable to accommodate powershell. cc @nodejs/child_process in case if anyone has concerns.

    @tkamenoko - are you willing to contribute through a PR?

  2. gireeshpunathil
    added
    feature requestIssues requesting new Node.js features.
    child_processIssues and PRs related to the child_process subsystem.
    on Jul 20, 2018
  3. richardlau commented on Jul 20, 2018

    @richardlau
    richardlau
    on Jul 20, 2018
    Member
    More actions

    Related: #19947

    Reacted by Gireesh Punathil
  4. tkamenoko commented on Jul 21, 2018

    @tkamenoko
    tkamenoko
    on Jul 21, 2018
    ContributorAuthor
    More actions

    @gireeshpunathil

    Yes, I want to contribute!

    Well, I have 2 questions before coding.
    1: Where should I place the test? test/pseudo-tty?
    2: Is it enough to test with cmd and powershell? Need git-bash?

    Thanks.

  5. gireeshpunathil commented on Jul 21, 2018

    @gireeshpunathil
    gireeshpunathil
    on Jul 21, 2018
    Member
    More actions

    awesome, thanks!

    Where should I place the test? test/pseudo-tty?

    test/parallel/test-chilld-process-*

    Is it enough to test with cmd and powershell? Need git-bash?

    would be great if you can cover git-bash too, while we are here.

  6. tkamenoko commented on Jul 21, 2018

    @tkamenoko
    tkamenoko
    on Jul 21, 2018
    ContributorAuthor
    More actions

    Thank you for the advice. I'll start working.

    Reacted by Gireesh Punathil
  7. tkamenoko
    added 2 commits that reference this issue on Jul 23, 2018

    child-process: fix switches for alternative shells on Windows

    0eb283a

    child-process: fix switches for alternative shells on Windows

    9c9fe57
  8. joaocgreis
    added a commit that references this issue on Sep 1, 2018

    child-process: fix switches for alternative shells on Windows

    b42be28
  9. joaocgreis
    closed this as completedin af883e1on Sep 5, 2018
  10. sjarmak
    added a commit that references this issue on Jul 27, 2026

    child_process: fix switches for alternative shells on Windows

    af883e1
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.feature requestIssues requesting new Node.js features.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.