Add $Shell:execute()

This commit is contained in:
Bruce Hill 2025-02-24 18:23:18 -05:00
parent 39295176a2
commit 928f3250b3
3 changed files with 8 additions and 0 deletions

View File

@ -380,6 +380,7 @@ env_t *new_compilation_unit(CORD libname)
{"escape_int", "Int$value_as_text", "func(i:Int -> Shell)"},
{"escape_text", "Shell$escape_text", "func(text:Text -> Shell)"},
{"escape_text_array", "Shell$escape_text_array", "func(texts:[Text] -> Shell)"},
{"execute", "Shell$execute", "func(command:Shell -> Int32)"},
{"run_bytes", "Shell$run", "func(command:Shell -> [Byte]?)"},
{"run", "Shell$run", "func(command:Shell -> Text?)"},
)},

View File

@ -75,6 +75,12 @@ public OptionalText_t Shell$run(Shell_t command)
return Text$from_bytes(bytes);
}
public int32_t Shell$execute(Shell_t command)
{
const char *cmd_str = Text$as_c_string(command);
return system(cmd_str);
}
static void _line_reader_cleanup(FILE **f)
{
if (f && *f) {

View File

@ -21,6 +21,7 @@ Shell_t Shell$escape_text(Text_t text);
Shell_t Shell$escape_text_array(Array_t texts);
OptionalArray_t Shell$run_bytes(Shell_t command);
OptionalText_t Shell$run(Shell_t command);
int32_t Shell$execute(Shell_t command);
#define Shell$hash Text$hash
#define Shell$compare Text$compare