From ec4d49f690a099dfba36282733cdacb7a3d2df12 Mon Sep 17 00:00:00 2001 From: itismadness Date: Fri, 30 Nov 2018 12:02:33 +0830 Subject: [PATCH] Use command -v for checking for programs --- src/Chardet.php | 3 ++- src/Util.php | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) 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) {