You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
15 lines
457 B
TypeScript
15 lines
457 B
TypeScript
4 years ago
|
import { spawn } from "child_process";
|
||
|
|
||
|
export default function simpleSpawn(cmd: string, arg: string[]) {
|
||
|
const process = spawn(cmd, arg);
|
||
|
let output = "";
|
||
|
let err = "";
|
||
|
return new Promise((resolve, reject) => {
|
||
|
process.on("close", (code) => {
|
||
|
code === 0 ? resolve(output) : reject(err);
|
||
|
});
|
||
|
process.stdout.on("data", (data) => (output += data.toString("utf-8")));
|
||
|
process.stderr.on("data", (data) => (err += data.toString("utf-8")));
|
||
|
});
|
||
|
}
|