aboutsummaryrefslogtreecommitdiff
path: root/stdlib
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib')
-rw-r--r--stdlib/shell.c10
-rw-r--r--stdlib/shell.h2
2 files changed, 8 insertions, 4 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)
diff --git a/stdlib/shell.h b/stdlib/shell.h
index a8f35f65..500bb043 100644
--- a/stdlib/shell.h
+++ b/stdlib/shell.h
@@ -21,7 +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);
+OptionalInt32_t Shell$execute(Shell_t command);
#define Shell$hash Text$hash
#define Shell$compare Text$compare