@@ -222,14 +222,22 @@ exports.execFile = function(file /*, args, options, callback*/) {
222
222
223
223
function errorhandler ( e ) {
224
224
ex = e ;
225
- child . stdout . destroy ( ) ;
226
- child . stderr . destroy ( ) ;
225
+
226
+ if ( child . stdout )
227
+ child . stdout . destroy ( ) ;
228
+
229
+ if ( child . stderr )
230
+ child . stderr . destroy ( ) ;
231
+
227
232
exithandler ( ) ;
228
233
}
229
234
230
235
function kill ( ) {
231
- child . stdout . destroy ( ) ;
232
- child . stderr . destroy ( ) ;
236
+ if ( child . stdout )
237
+ child . stdout . destroy ( ) ;
238
+
239
+ if ( child . stderr )
240
+ child . stderr . destroy ( ) ;
233
241
234
242
killed = true ;
235
243
try {
@@ -247,37 +255,42 @@ exports.execFile = function(file /*, args, options, callback*/) {
247
255
} , options . timeout ) ;
248
256
}
249
257
250
- child . stdout . addListener ( 'data' , function ( chunk ) {
251
- stdoutLen += chunk . length ;
252
-
253
- if ( stdoutLen > options . maxBuffer ) {
254
- ex = new Error ( 'stdout maxBuffer exceeded.' ) ;
255
- kill ( ) ;
256
- } else {
257
- if ( ! encoding )
258
- _stdout . push ( chunk ) ;
259
- else
260
- _stdout += chunk ;
261
- }
262
- } ) ;
263
-
264
- child . stderr . addListener ( 'data' , function ( chunk ) {
265
- stderrLen += chunk . length ;
266
-
267
- if ( stderrLen > options . maxBuffer ) {
268
- ex = new Error ( 'stderr maxBuffer exceeded.' ) ;
269
- kill ( ) ;
270
- } else {
271
- if ( ! encoding )
272
- _stderr . push ( chunk ) ;
273
- else
274
- _stderr += chunk ;
275
- }
276
- } ) ;
258
+ if ( child . stdout ) {
259
+ if ( encoding )
260
+ child . stdout . setEncoding ( encoding ) ;
261
+
262
+ child . stdout . addListener ( 'data' , function ( chunk ) {
263
+ stdoutLen += chunk . length ;
264
+
265
+ if ( stdoutLen > options . maxBuffer ) {
266
+ ex = new Error ( 'stdout maxBuffer exceeded' ) ;
267
+ kill ( ) ;
268
+ } else {
269
+ if ( ! encoding )
270
+ _stdout . push ( chunk ) ;
271
+ else
272
+ _stdout += chunk ;
273
+ }
274
+ } ) ;
275
+ }
277
276
278
- if ( encoding ) {
279
- child . stderr . setEncoding ( encoding ) ;
280
- child . stdout . setEncoding ( encoding ) ;
277
+ if ( child . stderr ) {
278
+ if ( encoding )
279
+ child . stderr . setEncoding ( encoding ) ;
280
+
281
+ child . stderr . addListener ( 'data' , function ( chunk ) {
282
+ stderrLen += chunk . length ;
283
+
284
+ if ( stderrLen > options . maxBuffer ) {
285
+ ex = new Error ( 'stderr maxBuffer exceeded' ) ;
286
+ kill ( ) ;
287
+ } else {
288
+ if ( ! encoding )
289
+ _stderr . push ( chunk ) ;
290
+ else
291
+ _stderr += chunk ;
292
+ }
293
+ } ) ;
281
294
}
282
295
283
296
child . addListener ( 'close' , exithandler ) ;
0 commit comments