Include stderr in simplespawner output

master
Kuba Orlik 4 years ago
parent 04d93c8240
commit 7ee6a21f38

@ -1,6 +1,6 @@
{ {
"name": "async-spawner", "name": "async-spawner",
"version": "0.1.6", "version": "0.1.7",
"description": "Simple process spawning utility for node.js", "description": "Simple process spawning utility for node.js",
"main": "./lib/index.js", "main": "./lib/index.js",
"types": "./@types/index.d.ts", "types": "./@types/index.d.ts",

@ -4,13 +4,13 @@ import Emittery from "emittery";
export default function simpleSpawn( export default function simpleSpawn(
cmd: string, cmd: string,
arg: string[] arg: string[]
): Promise<string> { ): Promise<{ stdout: string; stderr: string }> {
const process = spawn(cmd, arg); const process = spawn(cmd, arg);
let output = ""; let output = "";
let err = ""; let err = "";
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
process.on("close", (code) => { process.on("close", (code) => {
code === 0 ? resolve(output) : reject(err); code === 0 ? resolve({ stdout: output, stderr: err }) : reject(err);
}); });
process.stdout.on("data", (data) => (output += data.toString("utf-8"))); process.stdout.on("data", (data) => (output += data.toString("utf-8")));
process.stderr.on("data", (data) => (err += data.toString("utf-8"))); process.stderr.on("data", (data) => (err += data.toString("utf-8")));

Loading…
Cancel
Save