function errorhandler(e) {
ex = e;
- child.stdout.destroy();
- child.stderr.destroy();
+
+ if (child.stdout)
+ child.stdout.destroy();
+
+ if (child.stderr)
+ child.stderr.destroy();
+
exithandler();
}
function kill() {
- child.stdout.destroy();
- child.stderr.destroy();
+ if (child.stdout)
+ child.stdout.destroy();
+
+ if (child.stderr)
+ child.stderr.destroy();
killed = true;
try {
}, options.timeout);
}
- child.stdout.addListener('data', function(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) {
- stderrLen += chunk.length;
-
- if (stderrLen > options.maxBuffer) {
- ex = new Error('stderr maxBuffer exceeded.');
- kill();
- } else {
- if (!encoding)
- _stderr.push(chunk);
- else
- _stderr += chunk;
- }
- });
+ if (child.stdout) {
+ if (encoding)
+ child.stdout.setEncoding(encoding);
+
+ child.stdout.addListener('data', function(chunk) {
+ stdoutLen += chunk.length;
+
+ if (stdoutLen > options.maxBuffer) {
+ ex = new Error('stdout maxBuffer exceeded');
+ kill();
+ } else {
+ if (!encoding)
+ _stdout.push(chunk);
+ else
+ _stdout += chunk;
+ }
+ });
+ }
- if (encoding) {
- child.stderr.setEncoding(encoding);
- child.stdout.setEncoding(encoding);
+ if (child.stderr) {
+ if (encoding)
+ child.stderr.setEncoding(encoding);
+
+ child.stderr.addListener('data', function(chunk) {
+ stderrLen += chunk.length;
+
+ if (stderrLen > options.maxBuffer) {
+ ex = new Error('stderr maxBuffer exceeded');
+ kill();
+ } else {
+ if (!encoding)
+ _stderr.push(chunk);
+ else
+ _stderr += chunk;
+ }
+ });
}
child.addListener('close', exithandler);