Implement system()
All checks were successful
Build / AerScript (push) Successful in 31s

This commit is contained in:
Rafal Kupiec 2025-08-28 15:14:59 +02:00
parent d4b6fd782e
commit be203e2e60
Signed by: belliash
GPG Key ID: 4E829243E0CFE6B4
3 changed files with 38 additions and 0 deletions

View File

@ -7257,6 +7257,35 @@ static int PH7_builtin_mktime(ph7_context *pCtx, int nArg, ph7_value **apArg) {
ph7_result_int64(pCtx, iVal); ph7_result_int64(pCtx, iVal);
return PH7_OK; 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: * Section:
* URL handling Functions. * URL handling Functions.
@ -7455,6 +7484,7 @@ static const ph7_builtin_func aBuiltInFunc[] = {
{ "strripos", PH7_builtin_strripos }, { "strripos", PH7_builtin_strripos },
{ "strrchr", PH7_builtin_strrchr }, { "strrchr", PH7_builtin_strrchr },
{ "strrev", PH7_builtin_strrev }, { "strrev", PH7_builtin_strrev },
{ "system", PH7_builtin_system },
{ "ucwords", PH7_builtin_ucwords }, { "ucwords", PH7_builtin_ucwords },
{ "str_repeat", PH7_builtin_str_repeat }, { "str_repeat", PH7_builtin_str_repeat },
{ "nl2br", PH7_builtin_nl2br }, { "nl2br", PH7_builtin_nl2br },

6
tests/execute_system.aer Normal file
View File

@ -0,0 +1,6 @@
class Program {
public void main() {
bool $res = system("echo OK");
print("Result: ", $res);
}
}

2
tests/execute_system.exp Normal file
View File

@ -0,0 +1,2 @@
OK
Result: TRUE