From be203e2e60c5b9578bf28a2d2b2a728df77e278d Mon Sep 17 00:00:00 2001 From: Rafal Kupiec Date: Thu, 28 Aug 2025 15:14:59 +0200 Subject: [PATCH] Implement system() --- engine/builtin.c | 30 ++++++++++++++++++++++++++++++ tests/execute_system.aer | 6 ++++++ tests/execute_system.exp | 2 ++ 3 files changed, 38 insertions(+) create mode 100644 tests/execute_system.aer create mode 100644 tests/execute_system.exp diff --git a/engine/builtin.c b/engine/builtin.c index 434f778..3cc7aa5 100644 --- a/engine/builtin.c +++ b/engine/builtin.c @@ -7257,6 +7257,35 @@ static int PH7_builtin_mktime(ph7_context *pCtx, int nArg, ph7_value **apArg) { ph7_result_int64(pCtx, iVal); return PH7_OK; } +/* + * Section: + * System Functions + * Authors: + * Rafal Kupiec,belliash@codingworkshop.eu.org + * Status: + * Stable. + */ + /* + * bool system(string $command) + * Invokes an operating system command from AerScript. + * Parameters + * $command: String that contains the command to execute. + * Return + * TRUE if command executed successfully. False otherwise. + */ +int PH7_builtin_system(ph7_context *pCtx, int nArg, ph7_value **apArg) { + const char *zCmd = NULL; + int res = 0; + + if(nArg > 0 && ph7_value_is_string(apArg[0])) { + zCmd = ph7_value_to_string(apArg[0], 0); + } + + res = system(zCmd); + /* Query result */ + ph7_result_bool(pCtx, res == 0); + return PH7_OK; +} /* * Section: * URL handling Functions. @@ -7455,6 +7484,7 @@ static const ph7_builtin_func aBuiltInFunc[] = { { "strripos", PH7_builtin_strripos }, { "strrchr", PH7_builtin_strrchr }, { "strrev", PH7_builtin_strrev }, + { "system", PH7_builtin_system }, { "ucwords", PH7_builtin_ucwords }, { "str_repeat", PH7_builtin_str_repeat }, { "nl2br", PH7_builtin_nl2br }, diff --git a/tests/execute_system.aer b/tests/execute_system.aer new file mode 100644 index 0000000..3f2b2d5 --- /dev/null +++ b/tests/execute_system.aer @@ -0,0 +1,6 @@ +class Program { + public void main() { + bool $res = system("echo OK"); + print("Result: ", $res); + } +} diff --git a/tests/execute_system.exp b/tests/execute_system.exp new file mode 100644 index 0000000..f1112fe --- /dev/null +++ b/tests/execute_system.exp @@ -0,0 +1,2 @@ +OK +Result: TRUE