Created
December 22, 2015 11:17
-
-
Save s-shin/5371669c2339cefefa47 to your computer and use it in GitHub Desktop.
手抜きspawn wrapper
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
{spawn} = require "child_process" | |
runCommand = (cmd, args, opts) -> new Promise (resolve, reject) -> | |
p = spawn cmd, args, opts | |
buf = [] | |
p.stdout.on "data", (data) -> buf.push data | |
p.stderr.on "data", (data) -> buf.push data | |
p.on "error", reject | |
p.on "close", (code) -> | |
result = buf.join("").trim() | |
if code then reject result else resolve result | |
# パイプとか使いたい場合こちらが便利 | |
runCommandViaShell = (cmdStr, opts) -> runCommand "sh", ["-c", cmdStr], opts | |
module.exports = { | |
runCommand | |
runCommandViaShell | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment