Skip to content

Commit 631e2e3

Browse files
Use system shell when executing commands. Fixes #8.
1 parent 5af762e commit 631e2e3

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

utils.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,20 @@ var _ = require('lodash');
33
var Promise = require('bluebird');
44
var shellQuote = require('shell-quote');
55

6+
// Try to resolve path to shell.
7+
// We assume that Windows provides COMSPEC env variable
8+
// and other platforms provide SHELL env variable
9+
var SHELL_PATH = process.env.SHELL || process.env.COMSPEC;
10+
var EXECUTE_OPTION = process.env.COMSPEC !== undefined ? '/c' : '-c';
11+
12+
// XXX: Wrapping tos to a promise is a bit wrong abstraction. Maybe RX suits
13+
// better?
614
function run(cmd, opts) {
15+
if (!SHELL_PATH) {
16+
// If we cannot resolve shell, better to just crash
17+
throw new Error('$SHELL environment variable is not set.');
18+
}
19+
720
opts = _.merge({
821
pipe: true,
922
cwd: undefined,
@@ -18,9 +31,9 @@ function run(cmd, opts) {
1831

1932
return new Promise(function(resolve, reject) {
2033
var child;
21-
var parts = shellQuote.parse(cmd);
34+
2235
try {
23-
child = childProcess.spawn(_.head(parts), _.tail(parts), {
36+
child = childProcess.spawn(SHELL_PATH, [EXECUTE_OPTION, cmd], {
2437
cwd: opts.cwd,
2538
stdio: opts.pipe ? 'inherit' : null
2639
});

0 commit comments

Comments
 (0)