@@ -4,9 +4,9 @@ var Stream = require('net').Stream;
44var InternalChildProcess = process . binding ( 'child_process' ) . ChildProcess ;
55
66
7- var spawn = exports . spawn = function ( path , args , env , customFds ) {
7+ var spawn = exports . spawn = function ( path , args /*, options OR env, customFds */ ) {
88 var child = new ChildProcess ( ) ;
9- child . spawn ( path , args , env , customFds ) ;
9+ child . spawn . apply ( child , arguments ) ;
1010 return child ;
1111} ;
1212
@@ -55,7 +55,7 @@ exports.execFile = function (file /* args, options, callback */) {
5555 }
5656 }
5757
58- var child = spawn ( file , args , options . env ) ;
58+ var child = spawn ( file , args , { env : options . env } ) ;
5959 var stdout = "" ;
6060 var stderr = "" ;
6161 var killed = false ;
@@ -161,18 +161,32 @@ ChildProcess.prototype.kill = function (sig) {
161161} ;
162162
163163
164- ChildProcess . prototype . spawn = function ( path , args , env , customFds ) {
164+ ChildProcess . prototype . spawn = function ( path , args , options , customFds ) {
165165 args = args || [ ] ;
166- env = env || process . env ;
166+ options = options || { } ;
167+
168+ var cwd , env ;
169+ if ( options . cwd === undefined && options . env === undefined && options . customFds === undefined ) {
170+ // Deprecated API: (path, args, options, env, customFds)
171+ cwd = "" ;
172+ env = options || process . env ;
173+ customFds = customFds || [ - 1 , - 1 , - 1 ] ;
174+ }
175+ else {
176+ // Recommended API: (path, args, options)
177+ cwd = options . cwd || "" ;
178+ env = options . env || process . env ;
179+ customFds = options . customFds || [ - 1 , - 1 , - 1 ] ;
180+ }
181+
167182 var envPairs = [ ] ;
168183 var keys = Object . keys ( env ) ;
169184 for ( var index = 0 , keysLength = keys . length ; index < keysLength ; index ++ ) {
170185 var key = keys [ index ] ;
171186 envPairs . push ( key + "=" + env [ key ] ) ;
172187 }
173188
174- customFds = customFds || [ - 1 , - 1 , - 1 ] ;
175- var fds = this . fds = this . _internal . spawn ( path , args , envPairs , customFds ) ;
189+ var fds = this . fds = this . _internal . spawn ( path , args , cwd , envPairs , customFds ) ;
176190
177191 if ( customFds [ 0 ] === - 1 || customFds [ 0 ] === undefined ) {
178192 this . stdin . open ( fds [ 0 ] ) ;
0 commit comments