59 lines
2.0 KiB
JavaScript
59 lines
2.0 KiB
JavaScript
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||
|
// Licensed under the MIT license.
|
||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||
|
exports.stopProcess = exports.startDetachedProcess = exports.startProcess = void 0;
|
||
|
const tslib_1 = require("tslib");
|
||
|
const childProcess = require("child_process");
|
||
|
/* global process, console */
|
||
|
function startProcess(commandLine, verbose = false) {
|
||
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
||
|
return new Promise((resolve, reject) => {
|
||
|
if (verbose) {
|
||
|
console.log(`Starting: ${commandLine}`);
|
||
|
}
|
||
|
childProcess.exec(commandLine, (error, stdout /* eslint-disable-line @typescript-eslint/no-unused-vars */, stderr /* eslint-disable-line @typescript-eslint/no-unused-vars */) => {
|
||
|
if (error) {
|
||
|
reject(error);
|
||
|
}
|
||
|
else {
|
||
|
resolve();
|
||
|
}
|
||
|
});
|
||
|
});
|
||
|
});
|
||
|
}
|
||
|
exports.startProcess = startProcess;
|
||
|
function startDetachedProcess(commandLine, verbose = false) {
|
||
|
if (verbose) {
|
||
|
console.log(`Starting: ${commandLine}`);
|
||
|
}
|
||
|
const subprocess = childProcess.spawn(commandLine, [], {
|
||
|
detached: true,
|
||
|
shell: true,
|
||
|
stdio: "ignore",
|
||
|
windowsHide: false,
|
||
|
});
|
||
|
subprocess.on("error", (err) => {
|
||
|
console.log(`Unable to run command: ${commandLine}.\n${err}`);
|
||
|
});
|
||
|
subprocess.unref();
|
||
|
return subprocess;
|
||
|
}
|
||
|
exports.startDetachedProcess = startDetachedProcess;
|
||
|
function stopProcess(processId) {
|
||
|
if (processId) {
|
||
|
try {
|
||
|
if (process.platform === "win32") {
|
||
|
childProcess.spawn("taskkill", ["/pid", `${processId}`, "/f", "/t"]);
|
||
|
}
|
||
|
else {
|
||
|
process.kill(processId);
|
||
|
}
|
||
|
}
|
||
|
catch (err) {
|
||
|
console.log(`Unable to kill process id ${processId}: ${err}`);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
exports.stopProcess = stopProcess;
|
||
|
//# sourceMappingURL=process.js.map
|