Skip to content

Commit

Permalink
Merge pull request #9 from paulpflug/#7
Browse files Browse the repository at this point in the history
colorful piping
  • Loading branch information
keithamus committed Mar 2, 2015
2 parents b295fcb + ca0498a commit 51cddf4
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env node
'use strict';
var exec = require('child_process').exec;
var spawn = require('child_process').spawn;

function potentialExit (childCmd, code) {
code = code? (code.code || code) : code;
Expand All @@ -9,14 +8,19 @@ function potentialExit (childCmd, code) {
process.exit(code);
}
}
var sh = 'sh';
var shFlag = '-c';

if (process.platform === 'win32') {
sh = 'cmd';
shFlag = '/c';
}
process.argv.slice(2).forEach(function (childCmd) {
var child = exec(childCmd, {
cwd: process.cwd(),
var child = spawn(sh,[shFlag,childCmd], {
cwd: process.cwd,
env: process.env,
stdio: ['pipe', process.stdout, process.stderr]
})
.on('error', potentialExit.bind(null, childCmd))
.on('exit', potentialExit.bind(null, childCmd));
child.stderr.pipe(process.stderr);
child.stdout.pipe(process.stdout);
});

0 comments on commit 51cddf4

Please sign in to comment.