diff --git a/src/Chardet.php b/src/Chardet.php index 640b7a8..3a10da7 100644 --- a/src/Chardet.php +++ b/src/Chardet.php @@ -15,11 +15,12 @@ class Chardet { foreach ($this->executables as $executable) { if (Util::commandExists($executable)) { $this->executable = $executable; + break; } } if ($this->executable === null) { - throw new \RuntimeException('Chardet not installed'); + throw new \RuntimeException('chardet not installed'); } } diff --git a/src/Util.php b/src/Util.php index 72a1e22..a73666c 100644 --- a/src/Util.php +++ b/src/Util.php @@ -4,8 +4,10 @@ namespace OrpheusNET\Logchecker; class Util { public static function commandExists($cmd) { - $return = shell_exec(sprintf("which %s", escapeshellarg($cmd))); - return !empty($return); + $where = substr(strtolower(PHP_OS), 0, 3) === 'win' ? 'where' : 'command -v'; + + exec("{$where} {$cmd} 2>/dev/null", $output, $return_var); + return $return_var === 0; } public static function strposArray(string $haystack, array $needles) {