X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/db3ced17bbfff00411f506d8c84419c875959d5e..1bee151fe3ccfd21df1d809392d6eb52ce7925cb:/lib-php/Shell.php diff --git a/lib-php/Shell.php b/lib-php/Shell.php index 72f90735..4be13235 100644 --- a/lib-php/Shell.php +++ b/lib-php/Shell.php @@ -1,4 +1,12 @@ aEnv)) $this->aEnv = $_ENV; + if (!isset($this->aEnv)) { + $this->aEnv = $_ENV; + } $this->aEnv = array_merge($this->aEnv, array($sKey => $sVal), $_ENV); } return $this; @@ -48,7 +58,7 @@ class Shell return join(' ', $aEscaped); } - public function run() + public function run($bExitOnFail = false) { $sCmd = $this->escapedCmd(); // $aEnv does not need escaping, proc_open seems to handle it fine @@ -67,14 +77,16 @@ class Shell fclose($aPipes[0]); // no stdin $iStat = proc_close($hProc); - return $iStat; - } + if ($iStat != 0 && $bExitOnFail) { + exit($iStat); + } + return $iStat; + } private function escapeParam($sParam) { - if (preg_match('/^-*\w+$/', $sParam)) return $sParam; - return escapeshellarg($sParam); + return (preg_match('/^-*\w+$/', $sParam)) ? $sParam : escapeshellarg($sParam); } }