Child processes: support windowsVerbatimArguments option

v0.7.4-release
Bert Belder 2011-08-05 09:36:39 +02:00
parent 69ce415d38
commit 567470b136
2 changed files with 43 additions and 14 deletions

View File

@ -47,16 +47,43 @@ function createSocket(pipe, readable) {
return s;
}
function mergeOptions(target, overrides) {
if (overrides) {
var keys = Object.keys(overrides);
for (var i = 0, len = keys.length; i < len; i++) {
var k = keys[i];
if (overrides[k] !== undefined) {
target[k] = overrides[k];
}
}
}
return target;
}
exports.exec = function(command /*, options, callback */) {
var rest = Array.prototype.slice.call(arguments, 1);
var args;
if (process.platform == 'win32') {
args = ['cmd.exe', ['/c', command]].concat(rest);
var file, args, options, callback;
if (typeof arguments[1] === 'function') {
options = undefined;
callback = arguments[1];
} else {
args = ['/bin/sh', ['-c', command]].concat(rest);
options = arguments[1];
callback = arguments[2];
}
return exports.execFile.apply(this, args);
if (process.platform === 'win32') {
file = 'cmd.exe';
args = ['/s', '/c', '"' + command + '"'];
// Make a shallow copy before patching so we don't clobber the user's
// options object.
options = mergeOptions({}, options);
options.windowsVerbatimArguments = true;
} else {
file = '/bin/sh';
args = ['-c', command];
}
return exports.execFile(file, args, options, callback);
};
@ -87,17 +114,12 @@ exports.execFile = function(file /* args, options, callback */) {
}
// Merge optionArg into options
if (optionArg) {
var keys = Object.keys(options);
for (var i = 0, len = keys.length; i < len; i++) {
var k = keys[i];
if (optionArg[k] !== undefined) options[k] = optionArg[k];
}
}
mergeOptions(options, optionArg);
var child = spawn(file, args, {
cwd: options.cwd,
env: options.env
env: options.env,
windowsVerbatimArguments: !!options.windowsVerbatimArguments
});
var stdout = '';
@ -189,6 +211,7 @@ var spawn = exports.spawn = function(file, args, options) {
file: file,
args: args,
cwd: options ? options.cwd : null,
windowsVerbatimArguments: !!(options && options.windowsVerbatimArguments),
envPairs: envPairs
});

View File

@ -146,6 +146,12 @@ class ProcessWrap : public HandleWrap {
options.stderr_stream = stderr_wrap->UVHandle();
}
// options.windows_verbatim_arguments
#if defined(_WIN32) && !defined(__CYGWIN__)
options.windows_verbatim_arguments = js_options->
Get(String::NewSymbol("windowsVerbatimArguments"))->IsTrue();
#endif
int r = uv_spawn(&wrap->process_, options);
wrap->SetHandle((uv_handle_t*)&wrap->process_);