Expose cwd option to child_process.exec()

This commit is contained in:
Bert Belder 2010-08-05 06:06:46 +02:00 committed by Ryan Dahl
parent 94914135df
commit aaa1f451e6
3 changed files with 27 additions and 1 deletions

View File

@ -1054,6 +1054,7 @@ There is a second optional argument to specify several options. The default opti
, timeout: 0
, maxBuffer: 200*1024
, killSignal: 'SIGKILL'
, cwd: null
, env: null
}

View File

@ -28,6 +28,7 @@ exports.execFile = function (file /* args, options, callback */) {
, timeout: 0
, maxBuffer: 200*1024
, killSignal: 'SIGKILL'
, cwd: null
, env: null
};
var args, optionArg, callback;
@ -55,7 +56,7 @@ exports.execFile = function (file /* args, options, callback */) {
}
}
var child = spawn(file, args, {env: options.env});
var child = spawn(file, args, {cwd: options.cwd, env: options.env});
var stdout = "";
var stderr = "";
var killed = false;

View File

@ -0,0 +1,24 @@
require('../common');
var assert = require('assert');
var exec = require('child_process').exec;
var success_count = 0;
var error_count = 0;
child = exec('pwd', {cwd: "/dev"}, function (err, stdout, stderr) {
if (err) {
error_count++;
console.log('error!: ' + err.code);
console.log('stdout: ' + JSON.stringify(stdout));
console.log('stderr: ' + JSON.stringify(stderr));
assert.equal(false, err.killed);
} else {
success_count++;
assert.equal(true, /^\/dev\b/.test(stdout));
}
});
process.addListener('exit', function () {
assert.equal(1, success_count);
assert.equal(0, error_count);
});