Skip to content

child_process.spawn parity between windows and posix #10302

Closed
@papercuptech

Description

@papercuptech
  • Version: 7.2.0 (all?)
  • Platform: Windows
  • Subsystem: Child Process

On Posix:

test file:

#!/usr/bin/env bash
echo "hello"
$ chmod 755 test
node
> var cp = require('child_process')
undefined
> cp.spawnSync('test')
'hello\n'
>

On Windows:

test.cmd file:

echo "hello"
$ echo %PATHEXT%
.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
node
> var cp = require('child_process')
undefined
> cp.spawnSync('test')
null
> cp.spawnSync('test.cmd')
null
> cp.spawnSync('test', {shell:true})
'hello\n'

Windows uses PATHEXT, ASSOC, and FTYPE to achieve something similar to Posix using execute permission and shebangs.

On Windows, spawn() is not giving Windows a chance to query PATHEXT, ASSOC, FTYPE information to run test.cmd as an executable.

To fix, on Windows, spawn() should always launch using CMD, when {shell:undefined} (i.e. set it to true when undefined), so that CMD can correctly handle PATHEXT, ASSOC, and FTYPE configuration. This does mean real, binary executables won't be launched directly but this should have no perceivable impact on launch time or behavior. The benefit is increased parity between Posix and Windows behavior.

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.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions