Skip to content

Commit

Permalink
win: fix test-child-process-exec-cwd
Browse files Browse the repository at this point in the history
  • Loading branch information
ry committed Aug 2, 2011
1 parent a44748b commit 2908f32
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
7 changes: 6 additions & 1 deletion lib/child_process_uv.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,12 @@ function createSocket(pipe, readable) {

exports.exec = function(command /*, options, callback */) {
var rest = Array.prototype.slice.call(arguments, 1);
var args = ['/bin/sh', ['-c', command]].concat(rest);
var args;
if (process.platform == 'win32') {
args = ['cmd.exe', ['/c', command]].concat(rest);
} else {
args = ['/bin/sh', ['-c', command]].concat(rest);
}
return exports.execFile.apply(this, args);
};

Expand Down
15 changes: 13 additions & 2 deletions test/simple/test-child-process-exec-cwd.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,17 @@ var exec = require('child_process').exec;
var success_count = 0;
var error_count = 0;

var child = exec('pwd', {cwd: '/dev'}, function(err, stdout, stderr) {
var pwdcommand, dir;

if (process.platform == 'win32') {
pwdcommand = 'echo %cd%';
dir = 'c:\\windows';
} else {
pwdcommand = 'pwd';
dir = '/etc';
}

var child = exec(pwdcommand, {cwd: dir}, function(err, stdout, stderr) {
if (err) {
error_count++;
console.log('error!: ' + err.code);
Expand All @@ -35,7 +45,8 @@ var child = exec('pwd', {cwd: '/dev'}, function(err, stdout, stderr) {
assert.equal(false, err.killed);
} else {
success_count++;
assert.equal(true, /^\/dev\b/.test(stdout));
console.log(stdout);
assert.ok(stdout.indexOf(dir) == 0);
}
});

Expand Down

0 comments on commit 2908f32

Please sign in to comment.