Permalink
Browse files

Child processes: support windowsVerbatimArguments option

  • Loading branch information...
1 parent 69ce415 commit 567470b136c2b170b327e26f15a0e59de7dec250 @piscisaureus piscisaureus committed Aug 5, 2011
Showing with 43 additions and 14 deletions.
  1. +37 −14 lib/child_process_uv.js
  2. +6 −0 src/process_wrap.cc
View
@@ -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
@@ -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_);

0 comments on commit 567470b

Please sign in to comment.