Skip to content

Commit

Permalink
child_process, win: fix shell spawn with AutoRun
Browse files Browse the repository at this point in the history
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 <reis@janeasystems.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Josh Gavant <josh.gavant@outlook.com>
Reviewed-By: Rod Vagg <rod@vagg.org>
  • Loading branch information
bzoz authored and addaleax committed Sep 9, 2016
1 parent 88ed3d2 commit b90f3da
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions doc/api/child_process.md
Expand Up @@ -132,7 +132,7 @@ added: v0.1.90
* `encoding` {String} (Default: `'utf8'`) * `encoding` {String} (Default: `'utf8'`)
* `shell` {String} Shell to execute the command with * `shell` {String} Shell to execute the command with
(Default: `'/bin/sh'` on UNIX, `'cmd.exe'` on Windows, The shell should (Default: `'/bin/sh'` on UNIX, `'cmd.exe'` on Windows, The shell should
understand the `-c` switch on UNIX or `/s /c` on Windows. On Windows, understand the `-c` switch on UNIX or `/d /s /c` on Windows. On Windows,
command line parsing should be compatible with `cmd.exe`.) command line parsing should be compatible with `cmd.exe`.)
* `timeout` {Number} (Default: `0`) * `timeout` {Number} (Default: `0`)
* [`maxBuffer`][] {Number} largest amount of data (in bytes) allowed on * [`maxBuffer`][] {Number} largest amount of data (in bytes) allowed on
Expand Down Expand Up @@ -317,7 +317,7 @@ added: v0.1.90
* `shell` {Boolean|String} If `true`, runs `command` inside of a shell. Uses * `shell` {Boolean|String} If `true`, runs `command` inside of a shell. Uses
`'/bin/sh'` on UNIX, and `'cmd.exe'` on Windows. A different shell can be `'/bin/sh'` on UNIX, and `'cmd.exe'` on Windows. A different shell can be
specified as a string. The shell should understand the `-c` switch on UNIX, specified as a string. The shell should understand the `-c` switch on UNIX,
or `/s /c` on Windows. Defaults to `false` (no shell). or `/d /s /c` on Windows. Defaults to `false` (no shell).
* return: {ChildProcess} * return: {ChildProcess}


The `child_process.spawn()` method spawns a new process using the given The `child_process.spawn()` method spawns a new process using the given
Expand Down Expand Up @@ -619,7 +619,7 @@ added: v0.11.12
* `env` {Object} Environment key-value pairs * `env` {Object} Environment key-value pairs
* `shell` {String} Shell to execute the command with * `shell` {String} Shell to execute the command with
(Default: `'/bin/sh'` on UNIX, `'cmd.exe'` on Windows, The shell should (Default: `'/bin/sh'` on UNIX, `'cmd.exe'` on Windows, The shell should
understand the `-c` switch on UNIX or `/s /c` on Windows. On Windows, understand the `-c` switch on UNIX or `/d /s /c` on Windows. On Windows,
command line parsing should be compatible with `cmd.exe`.) command line parsing should be compatible with `cmd.exe`.)
* `uid` {Number} Sets the user identity of the process. (See setuid(2).) * `uid` {Number} Sets the user identity of the process. (See setuid(2).)
* `gid` {Number} Sets the group identity of the process. (See setgid(2).) * `gid` {Number} Sets the group identity of the process. (See setgid(2).)
Expand Down Expand Up @@ -672,7 +672,7 @@ added: v0.11.12
* `shell` {Boolean|String} If `true`, runs `command` inside of a shell. Uses * `shell` {Boolean|String} If `true`, runs `command` inside of a shell. Uses
`'/bin/sh'` on UNIX, and `'cmd.exe'` on Windows. A different shell can be `'/bin/sh'` on UNIX, and `'cmd.exe'` on Windows. A different shell can be
specified as a string. The shell should understand the `-c` switch on UNIX, specified as a string. The shell should understand the `-c` switch on UNIX,
or `/s /c` on Windows. Defaults to `false` (no shell). or `/d /s /c` on Windows. Defaults to `false` (no shell).
* return: {Object} * return: {Object}
* `pid` {Number} Pid of the child process * `pid` {Number} Pid of the child process
* `output` {Array} Array of results from stdio output * `output` {Array} Array of results from stdio output
Expand Down
2 changes: 1 addition & 1 deletion lib/child_process.js
Expand Up @@ -338,7 +338,7 @@ function normalizeSpawnArguments(file /*, args, options*/) {
if (process.platform === 'win32') { if (process.platform === 'win32') {
file = typeof options.shell === 'string' ? options.shell : file = typeof options.shell === 'string' ? options.shell :
process.env.comspec || 'cmd.exe'; process.env.comspec || 'cmd.exe';
args = ['/s', '/c', '"' + command + '"']; args = ['/d', '/s', '/c', '"' + command + '"'];
options.windowsVerbatimArguments = true; options.windowsVerbatimArguments = true;
} else { } else {
if (typeof options.shell === 'string') if (typeof options.shell === 'string')
Expand Down
4 changes: 2 additions & 2 deletions test/common.js
Expand Up @@ -241,7 +241,7 @@ exports.spawnPwd = function(options) {
var spawn = require('child_process').spawn; var spawn = require('child_process').spawn;


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


if (exports.isWindows) { if (exports.isWindows) {
return spawnSync('cmd.exe', ['/c', 'cd'], options); return spawnSync('cmd.exe', ['/d', '/c', 'cd'], options);
} else { } else {
return spawnSync('pwd', [], options); return spawnSync('pwd', [], options);
} }
Expand Down

0 comments on commit b90f3da

Please sign in to comment.