@@ -71,7 +71,8 @@ exports._forkChild = function(fd) {
7171
7272
7373function normalizeExecArgs ( command /*, options, callback*/ ) {
74- var file , args , options , callback ;
74+ let options ;
75+ let callback ;
7576
7677 if ( typeof arguments [ 1 ] === 'function' ) {
7778 options = undefined ;
@@ -81,25 +82,12 @@ function normalizeExecArgs(command /*, options, callback*/) {
8182 callback = arguments [ 2 ] ;
8283 }
8384
84- if ( process . platform === 'win32' ) {
85- file = process . env . comspec || 'cmd.exe' ;
86- args = [ '/s' , '/c' , '"' + command + '"' ] ;
87- // Make a shallow copy before patching so we don't clobber the user's
88- // options object.
89- options = util . _extend ( { } , options ) ;
90- options . windowsVerbatimArguments = true ;
91- } else {
92- file = '/bin/sh' ;
93- args = [ '-c' , command ] ;
94- }
95-
96- if ( options && options . shell )
97- file = options . shell ;
85+ // Make a shallow copy so we don't clobber the user's options object.
86+ options = Object . assign ( { } , options ) ;
87+ options . shell = typeof options . shell === 'string' ? options . shell : true ;
9888
9989 return {
100- cmd : command ,
101- file : file ,
102- args : args ,
90+ file : command ,
10391 options : options ,
10492 callback : callback
10593 } ;
@@ -109,7 +97,6 @@ function normalizeExecArgs(command /*, options, callback*/) {
10997exports . exec = function ( command /*, options, callback*/ ) {
11098 var opts = normalizeExecArgs . apply ( null , arguments ) ;
11199 return exports . execFile ( opts . file ,
112- opts . args ,
113100 opts . options ,
114101 opts . callback ) ;
115102} ;
@@ -123,7 +110,8 @@ exports.execFile = function(file /*, args, options, callback*/) {
123110 maxBuffer : 200 * 1024 ,
124111 killSignal : 'SIGTERM' ,
125112 cwd : null ,
126- env : null
113+ env : null ,
114+ shell : false
127115 } ;
128116
129117 // Parse the optional positional parameters.
@@ -153,6 +141,7 @@ exports.execFile = function(file /*, args, options, callback*/) {
153141 env : options . env ,
154142 gid : options . gid ,
155143 uid : options . uid ,
144+ shell : options . shell ,
156145 windowsVerbatimArguments : ! ! options . windowsVerbatimArguments
157146 } ) ;
158147
@@ -331,7 +320,23 @@ function normalizeSpawnArguments(file /*, args, options*/) {
331320 else if ( options === null || typeof options !== 'object' )
332321 throw new TypeError ( 'options argument must be an object' ) ;
333322
334- options = util . _extend ( { } , options ) ;
323+ // Make a shallow copy so we don't clobber the user's options object.
324+ options = Object . assign ( { } , options ) ;
325+
326+ if ( options . shell ) {
327+ const command = [ file ] . concat ( args ) . join ( ' ' ) ;
328+
329+ if ( process . platform === 'win32' ) {
330+ file = typeof options . shell === 'string' ? options . shell :
331+ process . env . comspec || 'cmd.exe' ;
332+ args = [ '/s' , '/c' , '"' + command + '"' ] ;
333+ options . windowsVerbatimArguments = true ;
334+ } else {
335+ file = typeof options . shell === 'string' ? options . shell : '/bin/sh' ;
336+ args = [ '-c' , command ] ;
337+ }
338+ }
339+
335340 args . unshift ( file ) ;
336341
337342 var env = options . env || process . env ;
@@ -492,12 +497,12 @@ function execFileSync(/*command, args, options*/) {
492497exports . execFileSync = execFileSync ;
493498
494499
495- function execSync ( /*command , options*/) {
500+ function execSync ( command /* , options*/) {
496501 var opts = normalizeExecArgs . apply ( null , arguments ) ;
497502 var inheritStderr = opts . options ? ! opts . options . stdio : true ;
498503
499- var ret = spawnSync ( opts . file , opts . args , opts . options ) ;
500- ret . cmd = opts . cmd ;
504+ var ret = spawnSync ( opts . file , opts . options ) ;
505+ ret . cmd = command ;
501506
502507 if ( inheritStderr && ret . stderr )
503508 process . stderr . write ( ret . stderr ) ;
0 commit comments