From 6db2b4cc1f2aa67cc274d01e36a5a57470bfba35 Mon Sep 17 00:00:00 2001 From: Joshua Ramon Enslin Date: Fri, 4 Dec 2020 21:33:11 +0100 Subject: [PATCH] Add MD_STD::exec_edit to run edit and pipe STDERR to a php exception --- MD_STD.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/MD_STD.php b/MD_STD.php index 327be44..abf98dd 100644 --- a/MD_STD.php +++ b/MD_STD.php @@ -431,6 +431,23 @@ final class MD_STD { } + /** + * Wrapper around exec, to be used with editing functions. + * Pipes STDERR to STDOUT and throws an Exception on any error. + * + * @param string $cmds Commands to run. + * + * @return void + */ + public static function exec_edit(string $cmds):void { + + $error = \exec($cmds . ' 2>&1'); + if (!empty($error)) { + throw new \Exception('Shell error: ' . $error); + } + + } + /** * Wrapper around levenshtein(), that only compares the first 250 * characters (levenshtein can't handle more than 255).