Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

child process execFile callback parameters #4122

Closed
rd13 opened this Issue Oct 12, 2012 · 2 comments

Comments

Projects
None yet
2 participants

rd13 commented Oct 12, 2012

var test = execFile('/tmp/test', function(error,stdout,stderr) {
console.log("error: " error); //null
console.log("stdout: " stdout); //null
console.log("stderr: " stderr); //contains the response?
});

The response from stderr: 2012-10-12 12:01:35.062 test[18972] Hello World

Using the execFile I seem to get null, null, stdout passed to my callback function.

What I expected to be in stdout, was in stderr.. I thought the callback parameters were the same for both exec() and execFile()?

Node v0.8.9

If I do:

test.stdout.on('data', function (data) {
  console.log('stdout: ' + data); //null
});

test.stderr.on('data', function (data) {
  console.log('stderr: ' + data); //The response
});

And a dump of 'test' in the callback function gives me:

{ _closesNeeded: 3,
  _closesGot: 3,
  signalCode: null,
  exitCode: 0,
  killed: false,
  _handle: null,
  pid: 18972,
  stdin: 
   { _handle: null,
     _pendingWriteReqs: 0,
     _flags: 0,
     _connectQueueSize: 0,
     destroyed: true,
     errorEmitted: false,
     bytesRead: 0,
     _bytesDispatched: 0,
     allowHalfOpen: undefined,
     writable: false,
     readable: false,
     _connecting: false,
     _connectQueue: null,
     _idleNext: null,
     _idlePrev: null,
     _idleTimeout: -1 },
  stdout: 
   { _handle: null,
     _pendingWriteReqs: 0,
     _flags: 1,
     _connectQueueSize: 0,
     destroyed: true,
     errorEmitted: false,
     bytesRead: 0,
     _bytesDispatched: 0,
     allowHalfOpen: undefined,
     writable: false,
     readable: false,
     _paused: false,
     _events: { close: [Function], data: [Function] },
     _decoder: 
      { encoding: 'utf8',
        surrogateSize: 3,
        charBuffer: <Buffer 48 8b 40 6f 48 b9>,
        charReceived: 0,
        charLength: 0 },
     _connecting: false,
     _connectQueue: null,
     _idleNext: null,
     _idlePrev: null,
     _idleTimeout: -1 },
  stderr: 
   { _handle: null,
     _pendingWriteReqs: 0,
     _flags: 1,
     _connectQueueSize: 0,
     destroyed: true,
     errorEmitted: false,
     bytesRead: 102,
     _bytesDispatched: 0,
     allowHalfOpen: undefined,
     writable: false,
     readable: false,
     _paused: false,
     _events: { close: [Function], data: [Function] },
     _decoder: 
      { encoding: 'utf8',
        surrogateSize: 3,
        charBuffer: <Buffer 0a 02 00 00 00 00>,
        charReceived: 0,
        charLength: 0 },
     _connecting: false,
     _connectQueue: null,
     _idleNext: null,
     _idlePrev: null,
     _idleTimeout: -1 },
  stdio: 
   [ { _handle: null,
       _pendingWriteReqs: 0,
       _flags: 0,
       _connectQueueSize: 0,
       destroyed: true,
       errorEmitted: false,
       bytesRead: 0,
       _bytesDispatched: 0,
       allowHalfOpen: undefined,
       writable: false,
       readable: false,
       _connecting: false,
       _connectQueue: null,
       _idleNext: null,
       _idlePrev: null,
       _idleTimeout: -1 },
     { _handle: null,
       _pendingWriteReqs: 0,
       _flags: 1,
       _connectQueueSize: 0,
       destroyed: true,
       errorEmitted: false,
       bytesRead: 0,
       _bytesDispatched: 0,
       allowHalfOpen: undefined,
       writable: false,
       readable: false,
       _paused: false,
       _events: [Object],
       _decoder: [Object],
       _connecting: false,
       _connectQueue: null,
       _idleNext: null,
       _idlePrev: null,
       _idleTimeout: -1 },
     { _handle: null,
       _pendingWriteReqs: 0,
       _flags: 1,
       _connectQueueSize: 0,
       destroyed: true,
       errorEmitted: false,
       bytesRead: 102,
       _bytesDispatched: 0,
       allowHalfOpen: undefined,
       writable: false,
       readable: false,
       _paused: false,
       _events: [Object],
       _decoder: [Object],
       _connecting: false,
       _connectQueue: null,
       _idleNext: null,
       _idlePrev: null,
       _idleTimeout: -1 } ],
  _events: 
   { close: [Function: exithandler],
     error: [Function: errorhandler] } }

@rd13 rd13 closed this Oct 12, 2012

@rd13 Can you write down short reason why you close? ;-)

rd13 commented Oct 15, 2012

@langpavel I'm unsure of the fix, I changed my code to the following:

compiler.list = function(callback){

exec("gcc -o /tmp/test /tmp/test.m -I /usr/include/GNUstep/ -L /usr/lib/GNUstep/ -lgnustep-base -fconstant-string-class=NSConstantString", 
    function (error, stdout, stderr) {
      if(!error && !stderr) {
        //Compile success
        execFile('/tmp/test', function(error, stdout, stderr) {
          if(!error && !stderr) {
            //Runtime success
            callback(stdout);
          } else {
            //Runtime failed
            callback(stderr || error);
          }
        });
      } else {
        //Compile failed
        callback(stderr || error);
      }

  });

}

Which now seems to work as expected, strange.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment