Skip to content

Commit aac2452

Browse files
committed
Fix a bug where quoted absolute paths on Windows wouldn't work. i.e. "C:\Program Files (x86)\file.exe" --foo=bar
1 parent 3c9ba19 commit aac2452

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/Command.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,19 @@ public function setCommand($command)
147147
$command = escapeshellcmd($command);
148148
}
149149
if ($this->getIsWindows()) {
150+
$position = null;
151+
150152
// Make sure to switch to correct drive like "E:" first if we have a full path in command
151-
$chdrive = (isset($command[1]) && $command[1]===':') ? $command[0].': && ' : '';
153+
if (isset($command[1]) && $command[1]===':') {
154+
$position = 1;
155+
// Could be a quoted absolute path because of spaces. i.e. "C:\Program Files (x86)\file.exe"
156+
} elseif (isset($command[2]) && $command[2]===':') {
157+
$position = 2;
158+
}
152159

153160
// Absolute path. If it's a relative path, let it slide.
154-
if ($chdrive) {
155-
$command = sprintf($chdrive.'cd %s && %s', escapeshellarg(dirname($command)), basename($command));
161+
if ($position) {
162+
$command = sprintf($command[$position - 1].'cd %s && %s', escapeshellarg(dirname($command)), basename($command));
156163
}
157164
}
158165
$this->_command = $command;

0 commit comments

Comments
 (0)