@@ -71,7 +71,8 @@ exports._forkChild = function(fd) {
71
71
72
72
73
73
function normalizeExecArgs ( command /*, options, callback*/ ) {
74
- var file , args , options , callback ;
74
+ let options ;
75
+ let callback ;
75
76
76
77
if ( typeof arguments [ 1 ] === 'function' ) {
77
78
options = undefined ;
@@ -81,25 +82,12 @@ function normalizeExecArgs(command /*, options, callback*/) {
81
82
callback = arguments [ 2 ] ;
82
83
}
83
84
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 ;
98
88
99
89
return {
100
- cmd : command ,
101
- file : file ,
102
- args : args ,
90
+ file : command ,
103
91
options : options ,
104
92
callback : callback
105
93
} ;
@@ -109,7 +97,6 @@ function normalizeExecArgs(command /*, options, callback*/) {
109
97
exports . exec = function ( command /*, options, callback*/ ) {
110
98
var opts = normalizeExecArgs . apply ( null , arguments ) ;
111
99
return exports . execFile ( opts . file ,
112
- opts . args ,
113
100
opts . options ,
114
101
opts . callback ) ;
115
102
} ;
@@ -123,7 +110,8 @@ exports.execFile = function(file /*, args, options, callback*/) {
123
110
maxBuffer : 200 * 1024 ,
124
111
killSignal : 'SIGTERM' ,
125
112
cwd : null ,
126
- env : null
113
+ env : null ,
114
+ shell : false
127
115
} ;
128
116
129
117
// Parse the optional positional parameters.
@@ -153,6 +141,7 @@ exports.execFile = function(file /*, args, options, callback*/) {
153
141
env : options . env ,
154
142
gid : options . gid ,
155
143
uid : options . uid ,
144
+ shell : options . shell ,
156
145
windowsVerbatimArguments : ! ! options . windowsVerbatimArguments
157
146
} ) ;
158
147
@@ -331,7 +320,23 @@ function normalizeSpawnArguments(file /*, args, options*/) {
331
320
else if ( options === null || typeof options !== 'object' )
332
321
throw new TypeError ( '"options" argument must be an object' ) ;
333
322
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
+
335
340
args . unshift ( file ) ;
336
341
337
342
var env = options . env || process . env ;
@@ -491,12 +496,12 @@ function execFileSync(/*command, args, options*/) {
491
496
exports . execFileSync = execFileSync ;
492
497
493
498
494
- function execSync ( /*command , options*/) {
499
+ function execSync ( command /* , options*/) {
495
500
var opts = normalizeExecArgs . apply ( null , arguments ) ;
496
501
var inheritStderr = opts . options ? ! opts . options . stdio : true ;
497
502
498
- var ret = spawnSync ( opts . file , opts . args , opts . options ) ;
499
- ret . cmd = opts . cmd ;
503
+ var ret = spawnSync ( opts . file , opts . options ) ;
504
+ ret . cmd = command ;
500
505
501
506
if ( inheritStderr )
502
507
process . stderr . write ( ret . stderr ) ;
0 commit comments