Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix executable path handling under windows #962

Merged
merged 1 commit into from
Sep 4, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions lib/monitor/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var noop = function () {};
var restart = null;
var psTree = require('ps-tree');
var hasPS = true;
var path = require('path');

// discover if the OS has `ps`, and therefore can use psTree
exec('ps', function (error) {
Expand Down Expand Up @@ -52,11 +53,23 @@ function run(options) {

var executable = cmd.executable;

// special logic for windows, as spaces in the paths need the path fragment
// quoted, so it reads: c:\"Program Files"\nodejs\node.exe
if (utils.isWindows && executable.indexOf(' ') !== -1) {
var re = /\\((\w+\s+)+\w+)(?=([\\\.]))(?=([^"]*"[^"]*")*[^"]*$)/g;
executable = executable.replace(re, '\\"$1"');
if (utils.isWindows) {
// under windows if the executable path contains a forward slash, that will
// fail with cmd.exe, so we need to normalize it
if (executable.indexOf('/') !== -1) {
executable = path.normalize(executable);
}

// if the executable path contains a space the whole string must be quoted
// to get windows treat it as 1 argument for cmd.exe
if (executable.indexOf(' ') !== -1 && executable[0] !== '\"'
&& executable[executable.length - 1] !== '\"') {
// remove all quotes from executable (possible backward compat hacks)
executable = executable.replace (/\"/g, '');

// add quotes to beginning and end of executable
executable = '\"' + executable + '\"';
}
}

var args = runCmd ? utils.stringify(executable, cmd.args) : ':';
Expand Down