Skip to content
This repository was archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
Child processes: support windowsVerbatimArguments option
Browse files Browse the repository at this point in the history
  • Loading branch information
piscisaureus committed Aug 5, 2011
1 parent 69ce415 commit 567470b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 14 deletions.
51 changes: 37 additions & 14 deletions lib/child_process_uv.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};


Expand Down Expand Up @@ -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 = '';
Expand Down Expand Up @@ -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
});

Expand Down
6 changes: 6 additions & 0 deletions src/process_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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_);
Expand Down

0 comments on commit 567470b

Please sign in to comment.