Created
April 24, 2018 22:29
-
-
Save alexsasharegan/ae67d09b1de5061b36b1e1ebb7cdf5c7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { spawn } = require("child_process"); | |
function stream_cmd(cmd, args, { stdout, stderr, close, error }, options = {}) { | |
const proc = spawn(cmd, args, options); | |
if (stdout) { | |
proc.stdout.on("data", stdout); | |
} | |
if (stderr) { | |
proc.stderr.on("data", stderr); | |
} | |
if (close) { | |
proc.on("close", close); | |
} | |
if (error) { | |
proc.on("error", error); | |
} | |
return proc; | |
} | |
stream_cmd("git", ["status"], { | |
close: code => console.log(`Exited with code:`, code), | |
error: err => console.error(`command failed:`, err), | |
stderr: buf => console.error(`stderr:`, String(buf)), | |
stdout: buf => console.log(`stdout:`, String(buf)), | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment