Add MD_STD::exec_edit to run edit and pipe STDERR to a php exception

This commit is contained in:
Joshua Ramon Enslin 2020-12-04 21:33:11 +01:00
parent 4c5097701f
commit 6db2b4cc1f
Signed by: jrenslin
GPG Key ID: 46016F84501B70AE

View File

@ -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).