Skip to content

child_process.spawnSync() seems to be truncating arguments containing '&' #6702

@jasholl

Description

@jasholl
  • Version: 5.10.1, 6.1.0
  • Platform: Win 10 x64
  • Subsystem:

Using the child_process.spawnSync() function call, the args I pass are being cut if they contain an & in them. Here's my snippet:

var child=require('child_process');
var args =[];
args [0]="a";
args [1]="b";
args [2]="\"a&b\"";
var r = child.spawnSync("c:/temp/test.cmd", args);
r.stdout.toString();

Here's the output:

> var child=require('child_process');
undefined
> var args =[];
undefined
> args [0]="a";
'a'
> args [1]="b";
'b'
> args [2]="\"a&b\"";
'"a&b"'
> var r = child.spawnSync("c:/temp/test.cmd", args);
undefined
> r.stdout.toString();
'\r\nC:\\Program Files\\nodejs6.1.0>echo args=a b "\\"a \r\nargs=a b "\\"a\r\n'

Notice that the 3rd arg, "a&b" is passed only as "a

here's the contents of test.cmd:

echo args=%*

And here's the same output from commandline:

C:\temp>test a b "a&b"

C:\temp>echo args=a b "a&b"
args=a b "a&b"

[edit: fixed formatting - bnoordhuis]

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
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions