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