Skip to content

Conversation

@vsemozhetbyt
Copy link
Contributor

@vsemozhetbytvsemozhetbyt commented May 10, 2017

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines
Affected core subsystem(s)

test, child_process

This is the first step to fix the #12773.

I've decided to start from the most whimsical one (section 4 in the #12773): parallel/test-spawn-cmd-named-pipe.js fails if spaces exist both in node.exe and the test paths. If there are no spaces or there are spaces only in one of the paths (either), the test passes.

If I get it right, the cause is the very complicated rules for cmd.exe command line syntax concerning spaces and quotes: see "Quote Characters in a command" here and "Examples:" here.

The fixed test passes with all 4 paths variants (spaceless + spaceless, spacy + spaceless, spaceless + spacy, and spacy + spacy).

Please, test in more environments and propose better fixes if you have some)

cc @nodejs/testing, @nodejs/platform-windows, @bnoordhuis, @cjihrig

@vsemozhetbytvsemozhetbyt added child_process Issues and PRs related to the child_process subsystem. test Issues and PRs related to the tests. windows Issues and PRs related to the Windows platform. labels May 10, 2017
@nodejs-github-botnodejs-github-bot added the test Issues and PRs related to the tests. label May 10, 2017
@vsemozhetbyt
Copy link
ContributorAuthor

@vsemozhetbyt
Copy link
ContributorAuthor

The test runs only on Windows and Windows is OK in CI. One Linux fail must be irrelevant.

Copy link
Contributor

@cjihrigcjihrig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we go this route, the test may need to be renamed since it no longer uses spawn().

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would quoting the args and specifying the shell work with spawn()?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tried and failed. It seems the args are re-quoted internally in an inappropriate way for this case. But I may miss some variants. Can anybody else test?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does windowsVerbatimArguments make a difference?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this documented? I can't find.

Copy link
ContributorAuthor

@vsemozhetbytvsemozhetbytMay 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've found out a way with spawn():

constargs=['/c',`""${process.execPath}"`,`"${__filename}"`,'child','<',stdinPipeName,'>',`${stdoutPipeName}"`];constchild=spawn(comspec,args,{shell: true});

But it seems strange. And we execute cmd.exe with cmd.exe first, if I get this right. Is this way better?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

windowsVerbatimArguments is not documented. See

if(process.platform==='win32'){
file=typeofoptions.shell==='string' ? options.shell :
process.env.comspec||'cmd.exe';
args=['/d','/s','/c','"'+command+'"'];
options.windowsVerbatimArguments=true;
.

When you run exec() or spawn() with shell: true, this code path is hit. It's probably what you're looking for.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another way:

constargs=[`"${__filename}"`,'child','<',stdinPipeName,'>',stdoutPipeName];constchild=spawn(`"${process.execPath}"`,args,{shell: true});

Slightly better maybe than the previous one.

Copy link
ContributorAuthor

@vsemozhetbytvsemozhetbytMay 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not work:

constargs=['/c',`"${process.execPath}"`,`"${__filename}"`,'child','<',stdinPipeName,'>',stdoutPipeName];constchild=spawn(comspec,args,{shell: true,windowsVerbatimArguments: true});

Should I prefer one of the beforementioned variants with spawn()?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variant in #12945 (comment) seems reasonable enough.

parallel/test-spawn-cmd-named-pipe.js failed with spaces both in node.exe and test paths.
@vsemozhetbyt
Copy link
ContributorAuthor

Copy link
Contributor

@refackrefack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM if CI is green

@refack
Copy link
Contributor

@vsemozhetbyt you could update the first comment, since you eventually found a way to use spawn
IMHO you could also change title to something simpler like: test: make test path-robust or path agnostic

@vsemozhetbytvsemozhetbyt changed the title test: make parallel/test-spawn-cmd-named-pipe.js path-independenttest: make a test path-independentMay 10, 2017
Copy link
Contributor

@cjihrigcjihrig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM pending CI

@vsemozhetbyt
Copy link
ContributorAuthor

@refack I've unified with the #12812

@vsemozhetbyt
Copy link
ContributorAuthor

Windows CI is green.

@vsemozhetbyt
Copy link
ContributorAuthor

Landed in 529e4f2

@vsemozhetbytvsemozhetbyt deleted the test-spawn-cmd-named-pipe branch May 12, 2017 08:37
vsemozhetbyt added a commit that referenced this pull request May 12, 2017
parallel/test-spawn-cmd-named-pipe.js failed with spaces both in node.exe and test paths. PR-URL: #12945 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
anchnk pushed a commit to anchnk/node that referenced this pull request May 19, 2017
parallel/test-spawn-cmd-named-pipe.js failed with spaces both in node.exe and test paths. PR-URL: nodejs#12945 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
@jasnelljasnell mentioned this pull request May 28, 2017
@gibfahngibfahn mentioned this pull request Jun 15, 2017
3 tasks
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

child_processIssues and PRs related to the child_process subsystem.testIssues and PRs related to the tests.windowsIssues and PRs related to the Windows platform.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

@vsemozhetbyt@refack@jasnell@cjihrig@MylesBorins@nodejs-github-bot