mirror of
https://github.com/peklaiho/madlisp.git
synced 2024-11-22 05:14:45 +00:00
add function: system
This commit is contained in:
parent
c39064a682
commit
c9a095a857
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user