-
Notifications
You must be signed in to change notification settings - Fork 30.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
child-process: support any shells on Windows #21943
Closed
Closed
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
b42be28
child-process: fix switches for alternative shells on Windows
tkamenoko e9863e6
child-process: fix lint errors
tkamenoko 6f3bccc
test: add exec-any-shells test
tkamenoko 6b9b090
test: fix exec-any-shell test for powershell
tkamenoko 1dcea34
child-process: enable to accept full path that contains spaces
tkamenoko c7163f8
child-process: undo unrelated style changes
tkamenoko a314340
test: remove hard coding path
tkamenoko ce7999a
test: fix spawnsync-shell to check correct options on Windows
tkamenoko 097c905
child-process: set windowsVerbatimArguments true for any shell
tkamenoko a4122b7
child-process: use case-insensitive comparison to check shell name
tkamenoko 27ba48f
test: add testcases to ensure uppercase shell name and complex commands
tkamenoko f93c796
test: fix to accept multiple lines output of `where bash`
tkamenoko ade01d9
test: revert windowsVerbatim flag, fix `isCmd` check in spawnsync-shell
tkamenoko 5a2c130
doc: update shell requirements in child_process
tkamenoko e2192a3
fixup: windowsVerbatimArguments
joaocgreis 7a10600
fixup: don't exhaust exec buffer
joaocgreis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
test/parallel/test-child-process-exec-any-shells-windows.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const cp = require('child_process'); | ||
const fs = require('fs'); | ||
const tmpdir = require('../common/tmpdir'); | ||
|
||
// This test is only relevant on Windows. | ||
if (!common.isWindows) | ||
common.skip('Windows specific test.'); | ||
|
||
// This test ensures that child_process.exec can work with any shells. | ||
|
||
tmpdir.refresh(); | ||
const tmpPath = `${tmpdir.path}\\path with spaces`; | ||
fs.mkdirSync(tmpPath); | ||
|
||
const test = (shell) => { | ||
cp.exec('echo foo bar', { shell: shell }, | ||
common.mustCall((error, stdout, stderror) => { | ||
assert.ok(!error && !stderror); | ||
assert.ok(stdout.includes('foo') && stdout.includes('bar')); | ||
})); | ||
}; | ||
const testCopy = (shellName, shellPath) => { | ||
// Copy the executable to a path with spaces, to ensure there are no issues | ||
// related to quoting of argv0 | ||
const copyPath = `${tmpPath}\\${shellName}`; | ||
fs.copyFileSync(shellPath, copyPath); | ||
test(copyPath); | ||
}; | ||
|
||
const system32 = `${process.env.SystemRoot}\\System32`; | ||
|
||
// Test CMD | ||
test(true); | ||
test('cmd'); | ||
testCopy('cmd.exe', `${system32}\\cmd.exe`); | ||
test('cmd.exe'); | ||
test('CMD'); | ||
|
||
// Test PowerShell | ||
test('powershell'); | ||
testCopy('powershell.exe', | ||
`${system32}\\WindowsPowerShell\\v1.0\\powershell.exe`); | ||
fs.writeFile(`${tmpPath}\\test file`, 'Test', common.mustCall((err) => { | ||
assert.ifError(err); | ||
cp.exec(`Get-ChildItem "${tmpPath}" | Select-Object -Property Name`, | ||
{ shell: 'PowerShell' }, | ||
common.mustCall((error, stdout, stderror) => { | ||
assert.ok(!error && !stderror); | ||
assert.ok(stdout.includes( | ||
'test file')); | ||
})); | ||
})); | ||
|
||
// Test Bash (from WSL and Git), if available | ||
cp.exec('where bash', common.mustCall((error, stdout) => { | ||
if (error) { | ||
return; | ||
} | ||
const lines = stdout.trim().split(/[\r\n]+/g); | ||
for (let i = 0; i < lines.length; ++i) { | ||
const bashPath = lines[i].trim(); | ||
test(bashPath); | ||
testCopy(`bash_${i}.exe`, bashPath); | ||
} | ||
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A late comment, I think that
\b
might be a simpler test for the prefix:also IMHO no need to
?:
the groups since we just.test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P.S. I would call my comment a "nit" (that is a non blocking style change)