mirror of
https://github.com/fofolee/uTools-ProcessKiller.git
synced 2025-06-09 15:04:09 +08:00
55 lines
1.2 KiB
JavaScript
55 lines
1.2 KiB
JavaScript
"use strict";
|
|
|
|
var spawn = require("child_process").spawn,
|
|
procOutput = require("proc-output");
|
|
|
|
/**
|
|
* spawno
|
|
* Creates the child process.
|
|
*
|
|
* @name spawno
|
|
* @function
|
|
* @param {String} command The command you want to run.
|
|
* @param {Array} args The command arguments.
|
|
* @param {Object} options The options to pass to the `spawn` function extended with:
|
|
*
|
|
* - `_showOutput` (Boolean): If truly, the output will be piped in the
|
|
* process stdout/stderr streams.
|
|
*
|
|
* @param {Function} cb The callback function.
|
|
* @returns {Process} The child process that was created.
|
|
*/
|
|
module.exports = function spawno(command, args, options, cb) {
|
|
|
|
if (typeof args === "function") {
|
|
cb = args;
|
|
args = [];
|
|
options = {};
|
|
}
|
|
|
|
if (typeof options === "function") {
|
|
cb = options;
|
|
if (!Array.isArray(args)) {
|
|
options = args;
|
|
args = [];
|
|
} else {
|
|
options = {};
|
|
}
|
|
}
|
|
|
|
var showOutput = options._showOutput;
|
|
delete options._showOutput;
|
|
|
|
var proc = spawn(command, args, options);
|
|
|
|
if (showOutput) {
|
|
proc.stdout.pipe(process.stdout);
|
|
proc.stderr.pipe(process.stderr);
|
|
}
|
|
|
|
if (cb) {
|
|
procOutput(proc, cb);
|
|
}
|
|
|
|
return proc;
|
|
}; |