diff --git a/src/_h5ai/server/php/inc/setup.php b/src/_h5ai/server/php/inc/setup.php index 74ac2645..3d22abc8 100644 --- a/src/_h5ai/server/php/inc/setup.php +++ b/src/_h5ai/server/php/inc/setup.php @@ -84,8 +84,15 @@ function setup() { // EXTERNAL COMMANDS - foreach (array("tar", "zip", "convert", "ffmpeg", "avconv", "du") as $cmd) { - $cmdv = HAS_WIN_OS ? array("which", $cmd) : array("command", "-v", $cmd); - define("HAS_CMD_" . strtoupper($cmd), @preg_match("#" . $cmd . "(.exe)?$#i", exec_cmdv($cmdv)) > 0); + // todo: cache all cmd tests + $cmd = false; + if (!$cmd && exec_0("command -v command")) { + $cmd = "command -v"; + } + if (!$cmd && exec_0("which which")) { + $cmd = "which"; + } + foreach (array("tar", "zip", "convert", "ffmpeg", "avconv", "du") as $c) { + define("HAS_CMD_" . strtoupper($c), ($cmd !== false) && exec_0($cmd . " " . $c)); } } diff --git a/src/_h5ai/server/php/inc/util.php b/src/_h5ai/server/php/inc/util.php index fc2d091f..4672bea8 100644 --- a/src/_h5ai/server/php/inc/util.php +++ b/src/_h5ai/server/php/inc/util.php @@ -96,6 +96,18 @@ function exec_cmdv($cmdv) { } +function exec_0($cmd) { + + $lines = array(); + $rc = null; + try { + @exec($cmd, $lines, $rc); + return $rc === 0; + } catch (Exception $e) {} + return false; +} + + /********************************************************************* Debug Tools