/*
spawn a process to run the command name
with commandline arguments args
call cb on completion
485821
function runCommand(name, args, options, cb, stdoutHandler, stderrHandler) {
	//if we dont actually have stdout and stderr, try to get the cb
	//if there was no callback passed, used a default

	options = options || { cwd : cwd, env: env };
	var child = spawn(name, args, options);
	if (cb) {
		var out = null;
		var err = null;
		//we need to wait for process.exit, stdout.end, and stderr.end before
		//we return
		var waiting = 3;
		var returnArgs = [];

		var fire = function(index, arg) {
			if (arg != null) {
				returnArgs[index] = arg;
			}
			if (--waiting === 0) {
				cb.apply(undefined, returnArgs);
			}
		};
		//buffer stdout and stderr to pass to the completion callback
		if (!stdoutHandler) {
			out = '';
			stdoutHandler = function(data) {
				out += data;
			};
		}
		if (!stderrHandler) {
			err = '';
			stderrHandler = function(data) {
				err += data;
			};
		}
		child.stdout.setEncoding('utf8');
		child.stdout.on('data', stdoutHandler); 
		child.stdout.on('end', function() {fire(1, out); });
				
		child.stderr.setEncoding('utf8');
		child.stderr.on('data', stderrHandler);
		child.stderr.on('end', function() {fire(2, err); });

		child.on('exit', function(code) {
			fire(0, code);
		});
	}

	return child;

}
612687
function executeCmd(cmd, debug, quitapp) {
    if (typeof cmd !== 'object') {
        throw new Error('Empty or invalid argument list!');
    }

    let finalcmd = cmd.join(' ');

    if (debug) {
        // debug mode, print to console
        console.log(`Debug shutdown command: ${finalcmd}`)
        if (quitapp) {
            console.log("Now exit app...");
            app.exit(0);
        }
    } else {
        cp.exec(finalcmd, (err, stdout, stderr) => {
            if (err) {
                console.error(err);
                return;
            }
            //console.log(stdout);
            if (quitapp) {
                app.exit(0);
            }
        });
    }
}
462406
async function CLI ({
  beforeParse,
  afterParse
}) {
  const cli = CAC()
  beforeParse && await beforeParse(cli)
  cli.parse(process.argv)
  afterParse && await afterParse(cli)
}
1142700
def run_command(args, asynchronous=False):
    """"""
    logging.info("Executing %s command %s.",
                 asynchronous and 'asynchronous' or 'synchronous', args)

    process = subprocess.Popen(args,
                               shell=True,
                               stdout=subprocess.PIPE,
                               stderr=subprocess.STDOUT)

    try:
        timeout = asynchronous and 1 or None
        output = process.communicate(timeout=timeout)[0].decode('utf8')
    except subprocess.TimeoutExpired:
        pass

    if asynchronous:
        return PopenOutput(None, 'Asynchronous call.')
    else:
        return PopenOutput(process.returncode, output)
790183
function SetupCLI(execName, packageJson, Commands, args) {
  assert(_.isString(execName), 'execName must be a string.');
  assert(_.isObject(packageJson), 'packageJson must be an object.');
  assert(_.isObject(Commands), 'Command collection must be an object.');
  assert(_.isObject(args), 'Arguments must be an object.');

  // --version or -v triggers npm version check.
  if (args.version || args.v) {
    const progName = packageJson.title || packageJson.name || process.argv[0];
    console.log(`${progName} ${ShowVersion(packageJson)}`);
    return process.exit(0);
  }

  // Remove 'color' flags if present.
  if ('color' in args) {
    delete args.color;
  }

  // The first positional (non-option) argument is the sub-command to run.
  const cmdName = _.first(args._);
  if (!cmdName) {
    console.error(GetCommandList(execName, packageJson, Commands));
    return process.exit(1);
  }
  const cmd = global.COMMAND = Commands[cmdName];
  if (!cmd) {
    console.error(col.fatal(`Unknown command "${col.bold(cmdName)}".`));
    return process.exit(1);
  }

  // Show command-specific help.
  if (args.help || args.h) {
    console.error(GetCommandUsage(execName, packageJson, cmd, args));
    return process.exit(1);
  }

  // Parse command-line parameters
  try {
    args = ParseArguments(cmd, args);
  } catch (e) {
    console.error(col.fatal(e.message));
    return process.exit(1);
  }

  return args;
}
772391
function runCmd(cmd, args, fn) {
    args = args || [];
    let runner = require('child_process').spawn(cmd, args, {
        // keep color
        stdio: 'inherit',
    });
    runner.on('close', function(code) {
        if (fn) {
            fn(code);
        }
    });
}
935129
function exec (cmd) {
  debug('executing cmd', cmd)
  child_process.exec(cmd, function (err, stdout, stderr) {
    debug('command completed')
  })
}
348776
function(args, options, cb) {

                args = !_.isArray(args) ? [args] : args;
                args = options && args.concat(helper.optsToArgs(options)) || args;

                var child = grunt.util.spawn({
                    cmd:"node",
                    args:args
                }, function (error, result, code) {
                    cb(error);
                });

                child.stdout.pipe(process.stdout);
                child.stderr.pipe(process.stderr);

            }
453268
function forkProc(cwd, cmd, args, cb) {
    var env = process.env
    if (typeof(cwd) === 'object') {
      cb = cmd
      var cmd = cwd.cmd
      var args = cwd.args
      // Merge/override any variables
      mergeObj(cwd.env, env)
      cwd = cwd.cwd
    }
    if (typeof(cmd) === 'string' && typeof(args) === 'function') {
      var split = cmd.split(/\s+/)
      cmd = split[0]
      cb = args
      args = split.slice(1)
    }
    var proc = spawn(cmd, args, {cwd: cwd, env: env})

    // per-process output buffers
    proc.stderrBuffer = ""
    proc.stdoutBuffer = ""
    proc.stdmergedBuffer = ""

    proc.stdout.setEncoding('utf8')
    proc.stderr.setEncoding('utf8')

    proc.stdout.on('data', function(buf) {
      proc.stdoutBuffer += buf
      proc.stdmergedBuffer += buf
      stdoutBuffer += buf
      stdmergedBuffer += buf
      updateStatus("deployUpdate" , {stdout:buf})
    })

    proc.stderr.on('data', function(buf) {
      proc.stderrBuffer += buf
      proc.stdmergedBuffer += buf
      stderrBuffer += buf
      stdmergedBuffer += buf
      updateStatus("deployUpdate", {stderr:buf})
    })

    proc.on('close', function(exitCode) {
      cb(exitCode)
    })

    return proc
  }
377687
def do_shell(self, arg):
        
        if self.cmdprefix:
            raise CmdError("prefix not allowed")

        # Try to use the environment to locate cmd.exe.
        # If not found, it's usually OK to just use the filename,
        # since cmd.exe is one of those "magic" programs that
        # can be automatically found by CreateProcess.
        shell = os.getenv('ComSpec', 'cmd.exe')

        # When given a command, run it and return.
        # When no command is given, spawn a shell.
        if arg:
            arg = '%s /c %s' % (shell, arg)
        else:
            arg = shell
        process = self.debug.system.start_process(arg, bConsole = True)
        process.wait()
587097
function runCmd(cmd) {
  return new Promise((resolve, reject) => {
    exec(cmd, {}, function(err, stdout) {
      if(err) {
        console.error(stdout);
        return reject(err);
      }

      return resolve(stdout);
    });
  });
}
339127
function debug(cmd) {
        // start node in debug mode
        childProcess = childProcess || require("child_process");

        var PATH_CWD = process.cwd();

        // splice out allume command
        process.argv.splice(0, 1);

        // find debug argument
        var debugIdx = -1;
        for (var a in process.argv) {
            if (process.argv[a] == "--debug") {
                debugIdx = a;
            }
            process.argv[a] = process.argv[a].replace(/"/g, "\"");
        }
        if (debugIdx >= 0) {
            process.argv.splice(debugIdx, 1);
        }
        if (!cmd["--debug"].port) {
            process.argv.splice(0, 0, "--debug-brk");
            //process.argv.splice(0, 0, "--inspect");
        }
        else {
            if (debugIdx >= 0) {
                process.argv.splice(debugIdx, 1);
            }
            process.argv.splice(0, 0, "--debug-brk=" + cmd["--debug"].port);
            //process.argv.splice(0, 0, "--inspect=" + cmd["--debug"].port);
        }
    

        var ls = childProcess.spawn("node", process.argv, {"cwd": PATH_CWD});

        ls.stdout.on("data", function(data) {
            console.log(data.toString().trim());
        });

        ls.stderr.on("data", function(data) {
            console.error(data.toString().trim());
        });

        return;
    }
993173
function run(cmd) {
        return function (callback, options) {
            grunt.verbose.or.ok("Executing " + cmd);
            exec(cmd, options || {}, function (error, stdout, stderr) {
                if (error) {
                    grunt.fatal("'" + cmd + "' failed with :" + stderr);
                } else {
                    grunt.verbose.writeln("Result of " + cmd + ':\n' + stdout);
                    callback();
                }
            });
        };
    }
380290
function run(params, command, callback)
{
  var terminator
    , requiresContext = isArrowFunction(command)
    ;

  // make sure callback is invoked in real async way
  callback = async(callback);

  // check provided function if it expected
  // to be run in async or sync way

  // expects no arguments, run it as sync function
  // unless it's function straight outta factory
  // has `.commandDescription` property
  //
  // Or it has one argument and requires context
  // must be arrow function with `context` argument
  if ((command.length === 0 || (command.length === 1 && requiresContext)) && !command.commandDescription)
  {
    runSync(this, command, callback);
  }
  else // or run it as async
  {
    // async function may return terminator function
    terminator = runAsync(this, command, callback);
  }

  // return provided terminator or empty function
  // if there is none
  return terminator || function() {};
}
1022184
function exec(cmd, args = [], silent = false) {
    return __awaiter(this, void 0, void 0, function* () {
        const response = [];
        return new Promise((resolve, reject) => {
            const exe = child_process_1.spawn(cmd, args, {
                env: process.env
            });
            exe.stdout.on('data', data => {
                response.push(data.toString());
                if (!silent) {
                    console.log(data.toString());
                }
            });
            exe.stderr.on('data', data => {
                if (!silent) {
                    console.error(data.toString());
                }
            });
            exe.on('exit', code => {
                if (code === 0) {
                    return resolve(response);
                }
                else {
                    if (!silent) {
                        console.error('Problem executing ' + cmd);
                    }
                    return reject();
                }
            });
        });
    });
}
1203970
def run_in_background(*args, &block)
      command_line = normalize_command_line(*args, &block)

      pid, out, err = spawn_process(command_line)
      Process.detach(pid)
      at_exit do
        kill_process(pid)
      end
      return collect_result(command_line, pid, out, err)
    end
1110780
function exec (cmd, callback) {
  debug('executing cmd', cmd)
  child_process.exec(cmd, function (err, stdout, stderr) {
    debug('command completed')
    if (err) {
      if (callback) {
        callback(err)
      }
    } else {
      if (callback) {
        callback(null, stdout, stderr)
      }
    }
  })
}