summaryrefslogtreecommitdiff
path: root/lib/child_process.js
diff options
context:
space:
mode:
authorTessei Kameyama <kamenoko315@ruri.waseda.jp>2018-07-21 21:24:08 +0900
committerJoão Reis <reis@janeasystems.com>2018-09-05 20:52:02 +0100
commitaf883e1f99598492474c13447e2a1895c0c6f1b7 (patch)
tree31096b4f6402dc8abe22d93a7a91975921c88554 /lib/child_process.js
parent3209679b7f9ec9bd3ffc6cf2c56c6c5583be6b87 (diff)
downloadnode-new-af883e1f99598492474c13447e2a1895c0c6f1b7.tar.gz
child_process: fix switches for alternative shells on Windows
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: https://github.com/nodejs/node/issues/21905 PR-URL: https://github.com/nodejs/node/pull/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>
Diffstat (limited to 'lib/child_process.js')
-rw-r--r--lib/child_process.js11
1 files changed, 8 insertions, 3 deletions
diff --git a/lib/child_process.js b/lib/child_process.js
index 2e9c71c1ef..2962f5cf05 100644
--- a/lib/child_process.js
+++ b/lib/child_process.js
@@ -469,14 +469,19 @@ function normalizeSpawnArguments(file, args, options) {
if (options.shell) {
const command = [file].concat(args).join(' ');
-
+ // Set the shell, switches, and commands.
if (process.platform === 'win32') {
if (typeof options.shell === 'string')
file = options.shell;
else
file = process.env.comspec || 'cmd.exe';
- args = ['/d', '/s', '/c', `"${command}"`];
- options.windowsVerbatimArguments = true;
+ // '/d /s /c' is used only for cmd.exe.
+ if (/^(?:.*\\)?cmd(?:\.exe)?$/i.test(file)) {
+ args = ['/d', '/s', '/c', `"${command}"`];
+ options.windowsVerbatimArguments = true;
+ } else {
+ args = ['-c', command];
+ }
} else {
if (typeof options.shell === 'string')
file = options.shell;