| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
| args = args.slice(0); | ||
| } else if (args !== undefined && | ||
| (args === null || typeof args !== 'object')) { | ||
| (args === null || typeof args !== 'object')) { |
There was a problem hiding this comment.
Can you undo unrelated style changes? They make review harder, break git blame, and tend to induce merge conflicts.
Sorry, something went wrong.
| test('cmd.exe'); | ||
| test('C:\\WINDOWS\\system32\\cmd.exe'); | ||
| test('powershell'); | ||
| test('C:\\Program Files\\Git\\bin\\bash.exe'); |
There was a problem hiding this comment.
Is it a build requirement to have git bash installed on Windows?
Sorry, something went wrong.
There was a problem hiding this comment.
Yes, git bash is one of prerequisites.
Basic Unix tools required for some tests, Git for Windows includes Git Bash and tools which can be included in the global PATH.
Sorry, something went wrong.
There was a problem hiding this comment.
bash for windows is not a build requirement, but ATM it's a requirement for running the test suite.
Lines 265 to 267 in 5384570
However it is not guaranteed to be at C:\\Program Files\\Git. This could be done by running where bash, and also skipping if it not found.
Sorry, something went wrong.
There was a problem hiding this comment.
We should not be assuming any paths, e.g. the SystemDrive might not be C:.
Sorry, something went wrong.
There was a problem hiding this comment.
Oh, I had a misunderstanding.
Well, can I use exec in the exec test? If not, is there a workaround?
// Replace the test L23 to the following.
cp.exec('where bash', (error, stdout) => {
if (error) {
return;
};
test(stdout.trim());
});
Sorry, something went wrong.
There was a problem hiding this comment.
Sure, or execSync.
Sorry, something went wrong.
Sorry, something went wrong.
| test('cmd.exe'); | ||
| test('C:\\WINDOWS\\system32\\cmd.exe'); | ||
| test('powershell'); | ||
| test('C:\\Program Files\\Git\\bin\\bash.exe'); |
There was a problem hiding this comment.
bash for windows is not a build requirement, but ATM it's a requirement for running the test suite.
Lines 265 to 267 in 5384570
However it is not guaranteed to be at C:\\Program Files\\Git. This could be done by running where bash, and also skipping if it not found.
Sorry, something went wrong.
|
node/test/parallel/test-child-process-spawnsync-shell.js Lines 59 to 61 in f5a2167 This test failed because it expects to use options like /d /s /c for any shells on Windows, but this PR changes this behavior. Is it OK to fix the test? |
Sorry, something went wrong.
|
yes, absolutely! |
Sorry, something went wrong.
|
Why did the test fail? I can't reproduce the error on my local repository.
|
Sorry, something went wrong.
|
@tkamenoko Don't worry about this one. It happens often on Travis |
Sorry, something went wrong.
|
@targos Thanks. |
Sorry, something went wrong.
|
started one more CI , to be certain. |
Sorry, something went wrong.
|
Does any of the documentation need updating? |
Sorry, something went wrong.
|
Maybe this fragment? |
Sorry, something went wrong.
|
Are http2 tests flaky? parallel/test-http2-pipe failed on win2008r2. It passed on my local (win10 64bit), but parallel/test-http2-client-upload failed instead. They both got the same error:
|
Sorry, something went wrong.
There was a problem hiding this comment.
@tkamenoko thanks for working on this! I left a few comments that I believe should be addressed, but other than that this is looking good.
I noticed you are adding commits with descriptions for your changes. Usually when we land PRs we squash into only one commit (or more in some cases). In this case, we can keep the title and description of the first commit, so I want to make sure you're OK with that. This can happen only when landing, having multiple commits here in the PR is great if we ever have to come back and understand where something came from.
This PR changes the behavior described in https://github.com/nodejs/node/blob/a4ce449bb7b0e2f9edba75baf2a2f652a6750454/doc/api/child_process.md#shell-requirements . Since child_process is marked as stable, this will have to be semver major, and that section has to be adjusted to reflect these changes. Let me know if you'd like me to suggest some concrete text.
Sorry, something went wrong.
| // '/d /s /c' is used only for cmd.exe. | ||
| if (file.endsWith('cmd.exe') || file.endsWith('cmd')) { | ||
| args = ['/d', '/s', '/c', `"${command}"`]; | ||
| options.windowsVerbatimArguments = true; |
There was a problem hiding this comment.
windowsVerbatimArguments should be set out of this if block, to be active for any shell (this is mentioned in the documentation for spawn)
Sorry, something went wrong.
| args = ['/d', '/s', '/c', `"${command}"`]; | ||
| options.windowsVerbatimArguments = true; | ||
| // '/d /s /c' is used only for cmd.exe. | ||
| if (file.endsWith('cmd.exe') || file.endsWith('cmd')) { |
There was a problem hiding this comment.
String comparison should be case insensitive
Sorry, something went wrong.
| if (error) { | ||
| return; | ||
| } | ||
| test(stdout.trim()); |
There was a problem hiding this comment.
The output of where can have more than one line (in my machine I have bash from git and WSL). There is an example of using where here, but it can probably be simplified for this case.
Sorry, something went wrong.
|
|
||
| test('cmd'); | ||
| test('cmd.exe'); | ||
| test('powershell'); |
There was a problem hiding this comment.
Can you also include a more complex PowerShell test (with quotes and pipes)? Something like
cp.exec(`Get-ChildItem "${__dirname}" | Select-Object -Property Name`,
{ shell: 'PowerShell' }, (error, stdout, stderror) => {
assert.ok(!error && !stderror);
assert.ok(stdout.includes('test-child-process-exec-any-shells-windows.js'));
});
Sorry, something went wrong.
|
@nodejs/platform-windows I like this as is, but when this lands people will start depending on this. So, now is a probably good time to discuss: do we want to have an explicit PowerShell case like the one this creates for CMD? Like CMD uses /D (#8063), PowerShell could have -NoProfile. And perhaps it would be useful to have -ExecutionPolicy Unrestricted to easily execute scripts. |
Sorry, something went wrong.
|
@joaocgreis I have 2 questions just to make sure: 1: I no longer need to write long descriptions when adding commits, right? Or, should I write descriptions? 2:
Do you mean that the code should be like this? if (file.endsWith('cmd.exe') || file.endsWith('cmd')) {// fix later
args = ['/d', '/s', '/c', `"${command}"`];
} else {
args = ['-c', command];
}
options.windowsVerbatimArguments = true;Thanks. |
Sorry, something went wrong.
|
1: no need to write descriptions, just needs to be clear to the person landing this what to do with the commit. I usually write something like fixup: small description. There is no established procedure around this, so as long as it's clear it's good. 2: yes, that looks correct to me. |
Sorry, something went wrong.
|
@tkamenoko can you make this more general? Not all shells will use -c as command, IMHO we should pass those extra shell args as an additional spawn option. |
Sorry, something went wrong.
|
@bzoz Sorry, I can't decide by myself. This PR changes Windows shell requirements to that like Unix, except for cmd.exe.
Your suggestion is interesting, but I don't know how to implement it without large fix. We need to discuss whether to accept shells that do not use -c. If you know shells like that, it will be helpful to get agreement. |
Sorry, something went wrong.
|
@bzoz I think of exec as a way to run a line as if typed on the specified shell, it should know what arguments to use for each shell. Having an option to specify arguments would be ok, but I think it can be done in another PR if anyone is interested. Or do you think this PR should block on that? Note that quoting of the command depends on the arguments. @tkamenoko your update looks good, but I'm having issues running the test locally. Please let me investigate. The documentation update is still needed in https://github.com/nodejs/node/blob/a4ce449bb7b0e2f9edba75baf2a2f652a6750454/doc/api/child_process.md#shell-requirements . I suggest something like this: The shell should understand the `-c` switch. If the shell is `'cmd.exe'`, it should understand the `/d /s /c` switches and command line parsing should be compatible. |
Sorry, something went wrong.
|
The shell argument thingy can be done in another PR, this PR can land as it is. |
Sorry, something went wrong.
|
Test failure is related: the full listing of our parallel folder is too big for the exec buffer. |
Sorry, something went wrong.
On Windows, normalizeSpawnArguments set "/d /s /c" for any shells. It cause exec and other methods are limited to cmd.exe as a shell. Powershell and git-bash are often used instead of cmd.exe, and they can recieve "-c" switch like unix shells. So normalizeSpawnArguments is changed to set "/d /s /c" for cmd.exe, and "-c" for others. Fixes: nodejs#21905
Modify indent, and replace doublequote to singlequote.
This test ensure that child_process.exec can work with any shells. Giving a shell name if $path is defined, or full path is given. Testing with cmd, powershell, and git-bash, but the test fails when testing with git-bash. Git-bash is usually placed at 'C:\Program Files\Git\bin\', and it has a space that cause the failure.
When giving 'echo foo bar' to powershell, the result contains a new line like: foo bar This commit enables to test with poweshell correctly.
Before this commit, if given path contained spaces, like 'Program Files', exec failed to find a shell. 'options.windowsVerbatimArguments' is used for cmd.exe only, and spaces are escaped correctly.
Auto-formatting cause unnecessary indentations. These style changes are removed.
test-child-process-any-shell uses `where` before testing with bash to remove hard coding path.
This test expected to use cmd.exe options even if the shell was powershell. This commit fixes to check correct options for shells other than cmd.exe.
|
@tkamenoko I pushed a commit to address the test failure. Feel free to change it or remove it if you don't agree with it. Rebased and new CI: https://ci.nodejs.org/job/node-test-pull-request/16929/ |
Sorry, something went wrong.
|
Landed in af883e1 Thanks for your contribution @tkamenoko ! |
Sorry, something went wrong.
On Windows, normalizeSpawnArguments set "/d /s /c" for any shells. It cause exec and other methods are limited to cmd.exe as a shell. Powershell and git-bash are often used instead of cmd.exe, and they can recieve "-c" switch like unix shells. So normalizeSpawnArguments is changed to set "/d /s /c" for cmd.exe, and "-c" for others. Fixes: #21905 PR-URL: #21943 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: João Reis <reis@janeasystems.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com>
|
In which version of node was this released? |
Sorry, something went wrong.
@ackvf It hasn't. This is semver-major so will be in Node.js 11. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
On Windows, child_process methods like exec supported only cmd.exe as the shell. This change enables these methods to accept any shells using -c switch like Unix shells.
Fixes: #21905
Checklist