Skip to content

Commit

Permalink
writeOptionsToFile to work on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
moisish authored and freekmurze committed Aug 3, 2022
1 parent e0d3455 commit f430a81
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/Browsershot.php
Original file line number Diff line number Diff line change
Expand Up @@ -892,11 +892,15 @@ protected function getFullCommand(array $command)

$binPath = $this->binPath ?: __DIR__.'/../bin/browser.js';

if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
$optionsCommand = $this->getOptionsCommand(json_encode($command));

if ($this->isWindows()) {
$fullCommand =
$nodeBinary.' '
.escapeshellarg($binPath).' '
.'"'.str_replace('"', '\"', (json_encode($command))).'"';
.'"'
.$optionsCommand
.'"';

return escapeshellcmd($fullCommand);
}
Expand All @@ -905,8 +909,6 @@ protected function getFullCommand(array $command)

$setNodePathCommand = $this->getNodePathCommand($nodeBinary);

$optionsCommand = $this->getOptionsCommand(json_encode($command));

return
$setIncludePathCommand.' '
.$setNodePathCommand.' '
Expand All @@ -931,8 +933,11 @@ protected function getOptionsCommand(string $command): string
{
if ($this->writeOptionsToFile) {
$temporaryOptionsFile = $this->createTemporaryOptionsFile($command);
$command = "-f {$temporaryOptionsFile}";
}

return escapeshellarg("-f {$temporaryOptionsFile}");
if ($this->isWindows()) {
return str_replace('"', '\"', $command);
}

return escapeshellarg($command);
Expand Down Expand Up @@ -970,4 +975,9 @@ public function initialPageNumber(int $initialPage = 1)
->setOption('initialPageNumber', ($initialPage - 1))
->pages($initialPage.'-');
}

private function isWindows()
{
return strtoupper(substr(PHP_OS, 0, 3)) === 'WIN';
}
}

0 comments on commit f430a81

Please sign in to comment.