Expose cwd option to child_process.exec()
This commit is contained in:
parent
94914135df
commit
aaa1f451e6
@ -1054,6 +1054,7 @@ There is a second optional argument to specify several options. The default opti
|
|||||||
, timeout: 0
|
, timeout: 0
|
||||||
, maxBuffer: 200*1024
|
, maxBuffer: 200*1024
|
||||||
, killSignal: 'SIGKILL'
|
, killSignal: 'SIGKILL'
|
||||||
|
, cwd: null
|
||||||
, env: null
|
, env: null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,6 +28,7 @@ exports.execFile = function (file /* args, options, callback */) {
|
|||||||
, timeout: 0
|
, timeout: 0
|
||||||
, maxBuffer: 200*1024
|
, maxBuffer: 200*1024
|
||||||
, killSignal: 'SIGKILL'
|
, killSignal: 'SIGKILL'
|
||||||
|
, cwd: null
|
||||||
, env: null
|
, env: null
|
||||||
};
|
};
|
||||||
var args, optionArg, callback;
|
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 stdout = "";
|
||||||
var stderr = "";
|
var stderr = "";
|
||||||
var killed = false;
|
var killed = false;
|
||||||
|
24
test/simple/test-child-process-exec-cwd.js
Normal file
24
test/simple/test-child-process-exec-cwd.js
Normal 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);
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user