index.js
function execute(argv, bin, args, req) {
  var config = this.configure();
  var errors = this.errors, scope = this, e;
  var dir = config.bin || dirname(argv[1]);
  var local = path.join(dir, bin);
  var exists = fs.existsSync(local);
  var data = {bin: bin, dir: dir, local: local, args: args};
  if(!exists) {
    e = new ExecError(errors.EEXEC_NOENT.message, [bin], errors.EEXEC_NOENT.code);
    e.data = data;
    throw e;
  }
  var stat = fs.statSync(local);
  var ps = spawn(local, args, {stdio: [0, 1, 'pipe']});
  req.process = ps;
  this.emit('exec', ps, local, args, req);
  ps.on('error', function(err){
    error(scope, err, [bin]);
  });
  // suppress the execvp() error so we can cleanly
  // present our own error message
  ps.stderr.on('data', function(data) {
    if(!/^execvp\(\)/.test(data.toString())) {
      process.stderr.write(data);
    }
  })
  ps.on('close', function (code, signal) {
    // NOTE: workaround for https://github.com/joyent/node/issues/3222
    // NOTE: assume child process exited gracefully on SIGINT
    if(signal == 'SIGINT') {
      return process.exit(0);
    }
    // TODO: remove this event?
    scope.emit('close', code, signal);
    if(config.exit) process.exit(code);
  });
  return ps;
}
function execute(argv, bin, args, req) {
  var config = this.configure();
  var errors = this.errors, scope = this, e;
  var dir = config.bin || dirname(argv[1]);
  var local = path.join(dir, bin);
  var exists = fs.existsSync(local);
  var data = {bin: bin, dir: dir, local: local, args: args};
  if(!exists) {
    e = new ExecError(errors.EEXEC_NOENT.message, [bin], errors.EEXEC_NOENT.code);
    e.data = data;
    throw e;
  }
  var stat = fs.statSync(local);
  var ps = spawn(local, args, {stdio: [0, 1, 'pipe']});
  req.process = ps;
  this.emit('exec', ps, local, args, req);
  ps.on('error', function(err){
    error(scope, err, [bin]);
  });
  // suppress the execvp() error so we can cleanly
  // present our own error message
  ps.stderr.on('data', function(data) {
    if(!/^execvp\(\)/.test(data.toString())) {
      process.stderr.write(data);
    }
  })
  ps.on('close', function (code, signal) {
    // NOTE: workaround for https://github.com/joyent/node/issues/3222
    // NOTE: assume child process exited gracefully on SIGINT
    if(signal == 'SIGINT') {
      return process.exit(0);
    }
    // TODO: remove this event?
    scope.emit('close', code, signal);
    if(config.exit) process.exit(code);
  });
  return ps;
}
function execute ( argv , bin , args , req ) { var config = this . configure ( ) ; var errors = this . errors , scope = this , e ; var dir = config . bin || dirname ( argv [ 1 ] ) ; var local = path . join ( dir , bin ) ; var exists = fs . existsSync ( local ) ; var data = { bin : bin , dir : dir , local : local , args : args } ; if ( ! exists ) { e = new ExecError ( errors . EEXEC_NOENT . message , [ bin ] , errors . EEXEC_NOENT . code ) ; e . data = data ; throw e ; } var stat = fs . statSync ( local ) ; var ps = spawn ( local , args , { stdio : [ 0 , 1 , 'pipe' ] } ) ; req . process = ps ; this . emit ( 'exec' , ps , local , args , req ) ; ps . on ( 'error' , function ( err ) { error ( scope , err , [ bin ] ) ; } ) ; // suppress the execvp() error so we can cleanly // present our own error message ps . stderr . on ( 'data' , function ( data ) { if ( ! / ^execvp\(\) / . test ( data . toString ( ) ) ) { process . stderr . write ( data ) ; } } ) ps . on ( 'close' , function ( code , signal ) { // NOTE: workaround for https://github.com/joyent/node/issues/3222 // NOTE: assume child process exited gracefully on SIGINT if ( signal == 'SIGINT' ) { return process . exit ( 0 ) ; } // TODO: remove this event? scope . emit ( 'close' , code , signal ) ; if ( config . exit ) process . exit ( code ) ; } ) ; return ps ; }
Execute a command as an external program.

@param argv The program arguments.
@param cmd The command to execute.
@param args Array of arguments to pass to the command.
@param req The request object for the middleware execution.
Execute a command as an external program .