diff --git a/src/Command.php b/src/Command.php index 0e09bc5..2f34fc1 100644 --- a/src/Command.php +++ b/src/Command.php @@ -148,8 +148,19 @@ public function setCommand($command) } if ($this->getIsWindows()) { // Make sure to switch to correct drive like "E:" first if we have a full path in command - $chdrive = (isset($command[1]) && $command[1]===':') ? $command[0].': && ' : ''; - $command = sprintf($chdrive.'cd %s && %s', escapeshellarg(dirname($command)), basename($command)); + if (isset($command[1]) && $command[1]===':') { + $position = 1; + // Could be a quoted absolute path because of spaces. i.e. "C:\Program Files (x86)\file.exe" + } elseif (isset($command[2]) && $command[2]===':') { + $position = 2; + } else { + $position = false; + } + + // Absolute path. If it's a relative path, let it slide. + if ($position) { + $command = sprintf($command[$position - 1].': && cd %s && %s', escapeshellarg(dirname($command)), basename($command)); + } } $this->_command = $command; return $this;