From f430a81b1b8e07f089046984ae0f53c9161b1477 Mon Sep 17 00:00:00 2001 From: Moisis Date: Wed, 3 Aug 2022 11:52:43 +0100 Subject: [PATCH] writeOptionsToFile to work on windows --- src/Browsershot.php | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/Browsershot.php b/src/Browsershot.php index b0dd253b..2eedd100 100644 --- a/src/Browsershot.php +++ b/src/Browsershot.php @@ -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); } @@ -905,8 +909,6 @@ protected function getFullCommand(array $command) $setNodePathCommand = $this->getNodePathCommand($nodeBinary); - $optionsCommand = $this->getOptionsCommand(json_encode($command)); - return $setIncludePathCommand.' ' .$setNodePathCommand.' ' @@ -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); @@ -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'; + } }