@ -611,8 +611,18 @@ exports.execFile = function(file /* args, options, callback */) {
windowsVerbatimArguments : ! ! options . windowsVerbatimArguments
windowsVerbatimArguments : ! ! options . windowsVerbatimArguments
} ) ;
} ) ;
var _ stdout = [ ] ;
var encoding ;
var _ stderr = [ ] ;
var _ stdout ;
var _ stderr ;
if ( options . encoding !== 'buffer' && Buffer . isEncoding ( options . encoding ) ) {
encoding = options . encoding ;
_ stdout = '' ;
_ stderr = '' ;
} else {
_ stdout = [ ] ;
_ stderr = [ ] ;
encoding = null ;
}
var stdoutLen = 0 ;
var stdoutLen = 0 ;
var stderrLen = 0 ;
var stderrLen = 0 ;
var killed = false ;
var killed = false ;
@ -633,13 +643,14 @@ exports.execFile = function(file /* args, options, callback */) {
if ( ! callback ) return ;
if ( ! callback ) return ;
// merge chunks
// merge chunks
var stdout = Buffer . concat ( _ stdout ) ;
var stdout ;
var stderr = Buffer . concat ( _ stderr ) ;
var stderr ;
if ( ! encoding ) {
if ( Buffer . isEncoding ( options . encoding ) ) {
stdout = Buffer . concat ( _ stdout ) ;
// convert to strings
stderr = Buffer . concat ( _ stderr ) ;
stdout = stdout . toString ( options . encoding ) ;
} else {
stderr = stderr . toString ( options . encoding ) ;
stdout = _ stdout ;
stderr = _ stderr ;
}
}
if ( ex ) {
if ( ex ) {
@ -683,25 +694,38 @@ exports.execFile = function(file /* args, options, callback */) {
}
}
child . stdout . addListener ( 'data' , function ( chunk ) {
child . stdout . addListener ( 'data' , function ( chunk ) {
_ stdout . push ( chunk ) ;
stdoutLen += chunk . length ;
stdoutLen += chunk . length ;
if ( stdoutLen > options . maxBuffer ) {
if ( stdoutLen > options . maxBuffer ) {
ex = new Error ( 'stdout maxBuffer exceeded.' ) ;
ex = new Error ( 'stdout maxBuffer exceeded.' ) ;
kill ( ) ;
kill ( ) ;
} else {
if ( ! encoding )
_ stdout . push ( chunk ) ;
else
_ stdout += chunk ;
}
}
} ) ;
} ) ;
child . stderr . addListener ( 'data' , function ( chunk ) {
child . stderr . addListener ( 'data' , function ( chunk ) {
_ stderr . push ( chunk ) ;
stderrLen += chunk . length ;
stderrLen += chunk . length ;
if ( stderrLen > options . maxBuffer ) {
if ( stderrLen > options . maxBuffer ) {
ex = new Error ( 'stderr maxBuffer exceeded.' ) ;
ex = new Error ( 'stderr maxBuffer exceeded.' ) ;
kill ( ) ;
kill ( ) ;
} else {
if ( ! encoding )
_ stderr . push ( chunk ) ;
else
_ stderr += chunk ;
}
}
} ) ;
} ) ;
if ( encoding ) {
child . stderr . setEncoding ( encoding ) ;
child . stdout . setEncoding ( encoding ) ;
}
child . addListener ( 'close' , exithandler ) ;
child . addListener ( 'close' , exithandler ) ;
child . addListener ( 'error' , errorhandler ) ;
child . addListener ( 'error' , errorhandler ) ;