From a7d4b7bc09c8e3dcf56412d10b5fcc3f9039cad9 Mon Sep 17 00:00:00 2001 From: Tom Kay Date: Fri, 17 Oct 2025 17:29:44 +0100 Subject: [PATCH] use proc_open by default --- src/Console/Commands/BuiltInWebServer.php | 26 ++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/Console/Commands/BuiltInWebServer.php b/src/Console/Commands/BuiltInWebServer.php index f7b9881..6b616f3 100644 --- a/src/Console/Commands/BuiltInWebServer.php +++ b/src/Console/Commands/BuiltInWebServer.php @@ -61,6 +61,25 @@ class BuiltInWebServer extends ConsoleCommand protected $_executeMethod = 'passthru'; + public function __construct($name = null) + { + parent::__construct($name); + $this->_executeMethod = function ($command, &$exitCode) { + if(System::commandExists('bash')) + { + // Use bash to execute if available, + // enables CTRL+C to also kill spawned process (cygwin issue) + $command = ['bash', '-c', $command]; + } + $p = proc_open($command, [STDIN, STDOUT, STDERR], $pipes); + if(is_resource($p)) + { + $exitCode = proc_close($p); + } + return $exitCode; + }; + } + protected function configure() { $this->setName('serve'); @@ -137,12 +156,9 @@ protected function _runCommand($command) { $exitCode = 0; $method = $this->_executeMethod; - if(System::commandExists('bash')) + if(!is_callable($method)) { - // Use bash to execute if available, - // enables CTRL+C to also kill spawned process (cygwin issue) - $command = addcslashes($command, "'"); - $command = "bash -c '$command'"; + throw new \Exception('method not callable'); } $method($command, $exitCode); return $exitCode;