Skip to content

Commit b90f3da

Browse files
bzozaddaleax
authored andcommitted
child_process, win: fix shell spawn with AutoRun
Under Windows system can be configured to execute a specific command each time a shell is spawned. Under some conditions this breaks the way node handles shell scripts under windows. This commit adds /d switch to spawn and spawnSync which disables this AutoRun functionality. Fixes: nodejs/node-v0.x-archive#25458 PR-URL: #8063 Reviewed-By: João Reis <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Josh Gavant <[email protected]> Reviewed-By: Rod Vagg <[email protected]>
1 parent 88ed3d2 commit b90f3da

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

doc/api/child_process.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ added: v0.1.90
132132
* `encoding` {String} (Default: `'utf8'`)
133133
* `shell` {String} Shell to execute the command with
134134
(Default: `'/bin/sh'` on UNIX, `'cmd.exe'` on Windows, The shell should
135-
understand the `-c` switch on UNIX or `/s /c` on Windows. On Windows,
135+
understand the `-c` switch on UNIX or `/d /s /c` on Windows. On Windows,
136136
command line parsing should be compatible with `cmd.exe`.)
137137
* `timeout` {Number} (Default: `0`)
138138
* [`maxBuffer`][] {Number} largest amount of data (in bytes) allowed on
@@ -317,7 +317,7 @@ added: v0.1.90
317317
* `shell` {Boolean|String} If `true`, runs `command` inside of a shell. Uses
318318
`'/bin/sh'` on UNIX, and `'cmd.exe'` on Windows. A different shell can be
319319
specified as a string. The shell should understand the `-c` switch on UNIX,
320-
or `/s /c` on Windows. Defaults to `false` (no shell).
320+
or `/d /s /c` on Windows. Defaults to `false` (no shell).
321321
* return: {ChildProcess}
322322

323323
The `child_process.spawn()` method spawns a new process using the given
@@ -619,7 +619,7 @@ added: v0.11.12
619619
* `env` {Object} Environment key-value pairs
620620
* `shell` {String} Shell to execute the command with
621621
(Default: `'/bin/sh'` on UNIX, `'cmd.exe'` on Windows, The shell should
622-
understand the `-c` switch on UNIX or `/s /c` on Windows. On Windows,
622+
understand the `-c` switch on UNIX or `/d /s /c` on Windows. On Windows,
623623
command line parsing should be compatible with `cmd.exe`.)
624624
* `uid` {Number} Sets the user identity of the process. (See setuid(2).)
625625
* `gid` {Number} Sets the group identity of the process. (See setgid(2).)
@@ -672,7 +672,7 @@ added: v0.11.12
672672
* `shell` {Boolean|String} If `true`, runs `command` inside of a shell. Uses
673673
`'/bin/sh'` on UNIX, and `'cmd.exe'` on Windows. A different shell can be
674674
specified as a string. The shell should understand the `-c` switch on UNIX,
675-
or `/s /c` on Windows. Defaults to `false` (no shell).
675+
or `/d /s /c` on Windows. Defaults to `false` (no shell).
676676
* return: {Object}
677677
* `pid` {Number} Pid of the child process
678678
* `output` {Array} Array of results from stdio output

lib/child_process.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ function normalizeSpawnArguments(file /*, args, options*/) {
338338
if (process.platform === 'win32') {
339339
file = typeof options.shell === 'string' ? options.shell :
340340
process.env.comspec || 'cmd.exe';
341-
args = ['/s', '/c', '"' + command + '"'];
341+
args = ['/d', '/s', '/c', '"' + command + '"'];
342342
options.windowsVerbatimArguments = true;
343343
} else {
344344
if (typeof options.shell === 'string')

test/common.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ exports.spawnPwd = function(options) {
241241
var spawn = require('child_process').spawn;
242242

243243
if (exports.isWindows) {
244-
return spawn('cmd.exe', ['/c', 'cd'], options);
244+
return spawn('cmd.exe', ['/d', '/c', 'cd'], options);
245245
} else {
246246
return spawn('pwd', [], options);
247247
}
@@ -252,7 +252,7 @@ exports.spawnSyncPwd = function(options) {
252252
const spawnSync = require('child_process').spawnSync;
253253

254254
if (exports.isWindows) {
255-
return spawnSync('cmd.exe', ['/c', 'cd'], options);
255+
return spawnSync('cmd.exe', ['/d', '/c', 'cd'], options);
256256
} else {
257257
return spawnSync('pwd', [], options);
258258
}

0 commit comments

Comments
 (0)