diff --git a/src/Lib/Core.php b/src/Lib/Core.php index 234c503..ba1ec74 100644 --- a/src/Lib/Core.php +++ b/src/Lib/Core.php @@ -19,6 +19,7 @@ use MadLisp\Reader; use MadLisp\Symbol; use MadLisp\Tokenizer; use MadLisp\UserFunc; +use MadLisp\Vector; class Core implements ILib { @@ -113,6 +114,24 @@ class Core implements ILib )); } + if (!$this->safemode) { + $env->set('system', new CoreFunc('system', 'Execute a command on the system.', 1, 1, + function (string $command) { + // Use passthru to capture the raw output + + ob_start(); + passthru($command, $status); + $output = ob_get_contents(); + ob_end_clean(); + + return new Vector([ + $status, + $output + ]); + } + )); + } + $env->set('throw', new CoreFunc('throw', 'Throw an exception. Takes one argument which is passed to catch.', 1, 1, function ($error) { throw new MadLispUserException($error);