diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-02-25 00:59:31 -0500 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-02-25 00:59:31 -0500 |
| commit | 9a62f8d6a6f8148deaea89e73d866439b588babb (patch) | |
| tree | 3984626fc4b246a6677939c228527bc285f0e6f6 /stdlib/shell.c | |
| parent | 928f3250b3914c88d105d8cf297c6b27a96ed5ad (diff) | |
Add $Shell.execute()
Diffstat (limited to 'stdlib/shell.c')
| -rw-r--r-- | stdlib/shell.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/stdlib/shell.c b/stdlib/shell.c index 08898acc..7c54950c 100644 --- a/stdlib/shell.c +++ b/stdlib/shell.c @@ -50,7 +50,7 @@ public OptionalArray_t Shell$run_bytes(Shell_t command) if (len + (size_t)just_read >= capacity) content = GC_REALLOC(content, (capacity *= 2)); - memcpy(&content[len], chunk, (size_t)just_read); + memcpy(content + len, chunk, (size_t)just_read); len += (size_t)just_read; } while (just_read == sizeof(chunk)); @@ -75,10 +75,14 @@ public OptionalText_t Shell$run(Shell_t command) return Text$from_bytes(bytes); } -public int32_t Shell$execute(Shell_t command) +public OptionalInt32_t Shell$execute(Shell_t command) { const char *cmd_str = Text$as_c_string(command); - return system(cmd_str); + int status = system(cmd_str); + if (WIFEXITED(status)) + return (OptionalInt32_t){.i=WEXITSTATUS(status)}; + else + return (OptionalInt32_t){.is_none=true}; } static void _line_reader_cleanup(FILE **f) |
