cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bhigg...@apache.org
Subject git commit: CB-6377 superspawn: always wrap non .exe with spaces to cmd with /s /c
Date Mon, 14 Apr 2014 13:21:06 GMT
Repository: cordova-cli
Updated Branches:
  refs/heads/master 6fd3cdeea -> de2500bf8


CB-6377 superspawn: always wrap non .exe with spaces to cmd with /s /c

To use /s, we need:
1. to pass a single argument containing all of our arguments (with quotes around the whole
thing).
2. to use spawnOpts.windowsVerbatimArguments so that nothing gets escaped.


Project: http://git-wip-us.apache.org/repos/asf/cordova-cli/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-cli/commit/de2500bf
Tree: http://git-wip-us.apache.org/repos/asf/cordova-cli/tree/de2500bf
Diff: http://git-wip-us.apache.org/repos/asf/cordova-cli/diff/de2500bf

Branch: refs/heads/master
Commit: de2500bf8c0264fb2f2cd8f0271405de8f393d24
Parents: 6fd3cde
Author: Josh Soref <jsoref@blackberry.com>
Authored: Sat Apr 12 20:49:26 2014 -0400
Committer: Josh Soref <jsoref@blackberry.com>
Committed: Sat Apr 12 20:49:27 2014 -0400

----------------------------------------------------------------------
 src/superspawn.js | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/de2500bf/src/superspawn.js
----------------------------------------------------------------------
diff --git a/src/superspawn.js b/src/superspawn.js
index c277aea..60c9fdc 100644
--- a/src/superspawn.js
+++ b/src/superspawn.js
@@ -24,6 +24,7 @@ var _ = require('underscore');
 var Q = require('q');
 var shell = require('shelljs');
 var events = require('./events');
+var iswin32 = process.platform == 'win32';
 
 // On Windows, spawn() for batch files requires absolute path & having the extension.
 function resolveWindowsExe(cmd) {
@@ -67,14 +68,18 @@ exports.spawn = function(cmd, args, opts) {
     var spawnOpts = {};
     var d = Q.defer();
 
-    if (process.platform == 'win32') {
+    if (iswin32) {
         cmd = resolveWindowsExe(cmd);
         // If we couldn't find the file, likely we'll end up failing,
         // but for things like "del", cmd will do the trick.
-        if (!fs.existsSync(cmd)) {
+        if (path.extname(cmd) != '.exe' && cmd.indexOf(' ') != -1) {
             // We need to use /s to ensure that spaces are parsed properly with cmd spawned
content
-            args = ['/s', '/c', cmd].concat(args);
+            args = [['/s', '/c', '"'+[cmd].concat(args).map(function(a){if (/^[^"].* .*[^"]/.test(a))
return '"'+a+'"'; return a;}).join(" ")+'"'].join(" ")];
             cmd = 'cmd';
+            spawnOpts.windowsVerbatimArguments = true;
+        } else if (!fs.existsSync(cmd)) {
+            // We need to use /s to ensure that spaces are parsed properly with cmd spawned
content
+            args = ['/s', '/c', cmd].concat(args);
         }
     }
 


Mime
View raw message