Skip to content

Commit 6ba2de6

Browse files
committed
Merge pull request #24 from jhen0409/patch-1
Pipe stdout, stderr
2 parents 2dafaff + 2e15ab2 commit 6ba2de6

File tree

1 file changed

+13
-21
lines changed

1 file changed

+13
-21
lines changed

lib/exec.js

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,25 @@ var objectAssign = require('object-assign');
44

55
module.exports = function exec(script) {
66

7-
// Grab the command section of the entered command
8-
var command = script.command.split(' ')[0];
9-
// Anything else is options
10-
var options = script.command.split(' ').slice(1);
11-
127
var argv = process.argv.splice(3);
13-
14-
options = options.concat(argv);
8+
var command = script.command + ' ' + argv.join(' ');
159

1610
script.env = script.env || {};
1711

1812
var env = objectAssign(process.env, script.env, dotenv);
1913

20-
console.log('to be executed:', command, options.join(' '));
21-
var command = spawn(command, options, {env: env});
22-
23-
command.stdout.on('data', function(data) {
24-
process.stdout.write(data);
25-
});
26-
27-
command.stderr.on('data', function(data) {
28-
process.stderr.write(data);
29-
});
30-
31-
command.on('error', function(err) {
32-
process.stderr.write(err);
33-
process.exit(err.code || 1);
14+
var sh = 'sh', shFlag = '-c';
15+
if (process.platform === 'win32') {
16+
sh = 'cmd';
17+
shFlag = '/c';
18+
}
19+
20+
console.log('to be executed:', command);
21+
spawn(sh, [shFlag, command], {
22+
env: env,
23+
stdio: ['pipe', process.stdout, process.stderr]
24+
}).on('close', function(code) {
25+
process.exit(code);
3426
});
3527

3628
}

0 commit comments

Comments
 (0)