From b90f3da9deaeda2b04a77af2e11a4b6d33a0c510 Mon Sep 17 00:00:00 2001 From: Bartosz Sosnowski Date: Wed, 10 Aug 2016 17:01:04 +0200 Subject: [PATCH] child_process, win: fix shell spawn with AutoRun MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: https://github.com/nodejs/node-v0.x-archive/issues/25458 PR-URL: https://github.com/nodejs/node/pull/8063 Reviewed-By: João Reis Reviewed-By: Colin Ihrig Reviewed-By: Anna Henningsen Reviewed-By: Josh Gavant Reviewed-By: Rod Vagg --- doc/api/child_process.md | 8 ++++---- lib/child_process.js | 2 +- test/common.js | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/doc/api/child_process.md b/doc/api/child_process.md index 33027468eaf543..a873aa26d5bf69 100644 --- a/doc/api/child_process.md +++ b/doc/api/child_process.md @@ -132,7 +132,7 @@ added: v0.1.90 * `encoding` {String} (Default: `'utf8'`) * `shell` {String} Shell to execute the command with (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`.) * `timeout` {Number} (Default: `0`) * [`maxBuffer`][] {Number} largest amount of data (in bytes) allowed on @@ -317,7 +317,7 @@ added: v0.1.90 * `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 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} The `child_process.spawn()` method spawns a new process using the given @@ -619,7 +619,7 @@ added: v0.11.12 * `env` {Object} Environment key-value pairs * `shell` {String} Shell to execute the command with (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`.) * `uid` {Number} Sets the user identity of the process. (See setuid(2).) * `gid` {Number} Sets the group identity of the process. (See setgid(2).) @@ -672,7 +672,7 @@ added: v0.11.12 * `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 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} * `pid` {Number} Pid of the child process * `output` {Array} Array of results from stdio output diff --git a/lib/child_process.js b/lib/child_process.js index 0362b5fde270a8..a7815ac85c3bbf 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -338,7 +338,7 @@ function normalizeSpawnArguments(file /*, args, options*/) { if (process.platform === 'win32') { file = typeof options.shell === 'string' ? options.shell : process.env.comspec || 'cmd.exe'; - args = ['/s', '/c', '"' + command + '"']; + args = ['/d', '/s', '/c', '"' + command + '"']; options.windowsVerbatimArguments = true; } else { if (typeof options.shell === 'string') diff --git a/test/common.js b/test/common.js index 3eaaccacc96738..a5094b1d433ebe 100644 --- a/test/common.js +++ b/test/common.js @@ -241,7 +241,7 @@ exports.spawnPwd = function(options) { var spawn = require('child_process').spawn; if (exports.isWindows) { - return spawn('cmd.exe', ['/c', 'cd'], options); + return spawn('cmd.exe', ['/d', '/c', 'cd'], options); } else { return spawn('pwd', [], options); } @@ -252,7 +252,7 @@ exports.spawnSyncPwd = function(options) { const spawnSync = require('child_process').spawnSync; if (exports.isWindows) { - return spawnSync('cmd.exe', ['/c', 'cd'], options); + return spawnSync('cmd.exe', ['/d', '/c', 'cd'], options); } else { return spawnSync('pwd', [], options); }