mirror of
https://github.com/lrsjng/h5ai.git
synced 2025-03-19 12:00:01 +01:00
Improve cmd checks.
This commit is contained in:
parent
237ae10be1
commit
98b2a2af09
@ -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));
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user