From e34f22a06bdd64d926aca5267c38885028cdcb1e Mon Sep 17 00:00:00 2001 From: Pavel Shevaev Date: Thu, 21 Jul 2022 11:33:01 +0300 Subject: [PATCH] Adding shell_get and migrating to Exception --- helpers.inc.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/helpers.inc.php b/helpers.inc.php index 131dddc..f9394de 100644 --- a/helpers.inc.php +++ b/helpers.inc.php @@ -377,7 +377,7 @@ function shell($cmd, &$out=null) { shell_try($cmd, $ret, $out); if($ret != 0) - throw new TaskmanException("Shell execution error(exit code $ret)"); + throw new Exception("Shell execution error(exit code $ret)"); } function shell_try($cmd, &$ret=null, &$out=null) @@ -391,6 +391,14 @@ function shell_try($cmd, &$ret=null, &$out=null) _execute_proc_cmd($cmd, $ret, $out); } +function shell_get($cmd, $as_string = true) +{ + exec($cmd, $out, $code); + if($code !== 0) + throw new Exception("Error($code) executing shell cmd '$cmd'"); + return $as_string ? implode("", $out) : $out; +} + function _execute_proc_cmd($cmd, &$ret, &$out) { //TODO: do we really need to redirect error stream?