lib/index.js
function run(cmd, args, opts, fn) {
  if (typeof opts === 'function') {
    fn = opts;
    opts = {};
  }

  if (typeof args === 'function') {
    fn = args;
    args = [];
    opts = {};
  }

  getBinPath(cmd, function(err, bin) {
    if (err) {
      return fn(err);
    }

    debug('running', {
      cmd: cmd,
      args: args
    });

    var output = [];
    var proc = spawn(bin, args, opts);
    proc.stdout.on('data', function(buf) {
      buf.toString('utf-8').split('\n').map(function(line) {
        debug('  %s> %s', cmd, line);
      });
      output.push(buf);
    });
    proc.stderr.on('data', function(buf) {
      buf.toString('utf-8').split('\n').map(function(line) {
        debug('  %s> %s', cmd, line);
      });
      output.push(buf);
    });

    proc.on('exit', function(code) {
      if (code !== 0) {
        debug('command failed!', {
          cmd: cmd,
          bin: bin,
          args: args,
          opts: opts,
          code: code,
          output: Buffer.concat(output).toString('utf-8')
        });
        fn(new Error('Command failed!  '
          + 'Please try again with debugging enabled.'), Buffer.concat(output).toString('utf-8'));
        return;
      }
      debug('completed! %j', {
        cmd: cmd,
        bin: bin,
        args: args,
        opts: opts,
        code: code
      });

      fn(null, Buffer.concat(output).toString('utf-8'));
    });
  });
}
function run(cmd, args, opts, fn) {
  if (typeof opts === 'function') {
    fn = opts;
    opts = {};
  }

  if (typeof args === 'function') {
    fn = args;
    args = [];
    opts = {};
  }

  getBinPath(cmd, function(err, bin) {
    if (err) {
      return fn(err);
    }

    debug('running', {
      cmd: cmd,
      args: args
    });

    var output = [];
    var proc = spawn(bin, args, opts);
    proc.stdout.on('data', function(buf) {
      buf.toString('utf-8').split('\n').map(function(line) {
        debug('  %s> %s', cmd, line);
      });
      output.push(buf);
    });
    proc.stderr.on('data', function(buf) {
      buf.toString('utf-8').split('\n').map(function(line) {
        debug('  %s> %s', cmd, line);
      });
      output.push(buf);
    });

    proc.on('exit', function(code) {
      if (code !== 0) {
        debug('command failed!', {
          cmd: cmd,
          bin: bin,
          args: args,
          opts: opts,
          code: code,
          output: Buffer.concat(output).toString('utf-8')
        });
        fn(new Error('Command failed!  '
          + 'Please try again with debugging enabled.'), Buffer.concat(output).toString('utf-8'));
        return;
      }
      debug('completed! %j', {
        cmd: cmd,
        bin: bin,
        args: args,
        opts: opts,
        code: code
      });

      fn(null, Buffer.concat(output).toString('utf-8'));
    });
  });
}
function run ( cmd , args , opts , fn ) { if ( typeof opts === 'function' ) { fn = opts ; opts = { } ; } if ( typeof args === 'function' ) { fn = args ; args = [ ] ; opts = { } ; } getBinPath ( cmd , function ( err , bin ) { if ( err ) { return fn ( err ) ; } debug ( 'running' , { cmd : cmd , args : args } ) ; var output = [ ] ; var proc = spawn ( bin , args , opts ) ; proc . stdout . on ( 'data' , function ( buf ) { buf . toString ( 'utf-8' ) . split ( '\n' ) . map ( function ( line ) { debug ( '  %s> %s' , cmd , line ) ; } ) ; output . push ( buf ) ; } ) ; proc . stderr . on ( 'data' , function ( buf ) { buf . toString ( 'utf-8' ) . split ( '\n' ) . map ( function ( line ) { debug ( '  %s> %s' , cmd , line ) ; } ) ; output . push ( buf ) ; } ) ; proc . on ( 'exit' , function ( code ) { if ( code !== 0 ) { debug ( 'command failed!' , { cmd : cmd , bin : bin , args : args , opts : opts , code : code , output : Buffer . concat ( output ) . toString ( 'utf-8' ) } ) ; fn ( new Error ( 'Command failed!  ' + 'Please try again with debugging enabled.' ) , Buffer . concat ( output ) . toString ( 'utf-8' ) ) ; return ; } debug ( 'completed! %j' , { cmd : cmd , bin : bin , args : args , opts : opts , code : code } ) ; fn ( null , Buffer . concat ( output ) . toString ( 'utf-8' ) ) ; } ) ; } ) ; }
Use me when you want to run an external command instead
of using `child_process` directly because I'll handle
lots of platform edge cases for you and provide
nice debugging output when things go wrong!

@example
var run = require('electron-installer-run');
var args = ['--verify', process.env.APP_PATH];
run('codesign', args, function(err){
if(err){
console.error('codesign verification failed!');
process.exit(1);
}
console.log('codesign verification succeeded!');
});

@param {String} cmd - The bin name of your command, e.g. `grep`.
@param {Array} [args] - Arguments to pass to the command [Default `[]`].
@param {Object} [opts] - Options to pass to `child_process.spawn` [Default `{}`].
@param {Function} fn - Callback which recieves `(err, output)`.
Use me when you want to run an external command instead of using child_process directly because I ll handle lots of platform edge cases for you and provide nice debugging output when things go wrong!