mirror of https://github.com/janet-lang/janet
Add :x flag to os/execute.
This commit is contained in:
parent
301cbb0e68
commit
8b9ad2dce8
|
@ -2,6 +2,7 @@
|
||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
## Unreleased - ???
|
## Unreleased - ???
|
||||||
|
- Add `:x` flag to os/execute to raise error when exit code is non-zero.
|
||||||
- Don't run `main` when flychecking.
|
- Don't run `main` when flychecking.
|
||||||
- Add `:n` flag to `file/open` to raise an error if file cannot be opened.
|
- Add `:n` flag to `file/open` to raise an error if file cannot be opened.
|
||||||
- Fix import macro to not try and coerce everything to a string.
|
- Fix import macro to not try and coerce everything to a string.
|
||||||
|
|
|
@ -318,7 +318,7 @@ static Janet os_execute(int32_t argc, Janet *argv) {
|
||||||
/* Get flags */
|
/* Get flags */
|
||||||
uint64_t flags = 0;
|
uint64_t flags = 0;
|
||||||
if (argc > 1) {
|
if (argc > 1) {
|
||||||
flags = janet_getflags(argv, 1, "ep");
|
flags = janet_getflags(argv, 1, "epx");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get environment */
|
/* Get environment */
|
||||||
|
@ -365,8 +365,6 @@ static Janet os_execute(int32_t argc, Janet *argv) {
|
||||||
if (-1 == status) {
|
if (-1 == status) {
|
||||||
janet_panicf("%p: %s", argv[0], strerror(errno));
|
janet_panicf("%p: %s", argv[0], strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
return janet_wrap_integer(status);
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
const char **child_argv = janet_smalloc(sizeof(char *) * ((size_t) exargs.len + 1));
|
const char **child_argv = janet_smalloc(sizeof(char *) * ((size_t) exargs.len + 1));
|
||||||
|
@ -410,16 +408,18 @@ static Janet os_execute(int32_t argc, Janet *argv) {
|
||||||
|
|
||||||
os_execute_cleanup(envp, child_argv);
|
os_execute_cleanup(envp, child_argv);
|
||||||
/* Use POSIX shell semantics for interpreting signals */
|
/* Use POSIX shell semantics for interpreting signals */
|
||||||
int ret;
|
|
||||||
if (WIFEXITED(status)) {
|
if (WIFEXITED(status)) {
|
||||||
ret = WEXITSTATUS(status);
|
status = WEXITSTATUS(status);
|
||||||
} else if (WIFSTOPPED(status)) {
|
} else if (WIFSTOPPED(status)) {
|
||||||
ret = WSTOPSIG(status) + 128;
|
status = WSTOPSIG(status) + 128;
|
||||||
} else {
|
} else {
|
||||||
ret = WTERMSIG(status) + 128;
|
status = WTERMSIG(status) + 128;
|
||||||
}
|
}
|
||||||
return janet_wrap_integer(ret);
|
|
||||||
#endif
|
#endif
|
||||||
|
if (janet_flag_at(flags, 2) && status) {
|
||||||
|
janet_panicf("command failed with non-zero exit code %d", status);
|
||||||
|
}
|
||||||
|
return janet_wrap_integer(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Janet os_shell(int32_t argc, Janet *argv) {
|
static Janet os_shell(int32_t argc, Janet *argv) {
|
||||||
|
@ -1334,7 +1334,8 @@ static const JanetReg os_cfuns[] = {
|
||||||
"\t:e - enables passing an environment to the program. Without :e, the "
|
"\t:e - enables passing an environment to the program. Without :e, the "
|
||||||
"current environment is inherited.\n"
|
"current environment is inherited.\n"
|
||||||
"\t:p - allows searching the current PATH for the binary to execute. "
|
"\t:p - allows searching the current PATH for the binary to execute. "
|
||||||
"Without this flag, binaries must use absolute paths.\n\n"
|
"Without this flag, binaries must use absolute paths.\n"
|
||||||
|
"\t:x - raise error if exit code is non-zero.\n\n"
|
||||||
"env is a table or struct mapping environment variables to values. "
|
"env is a table or struct mapping environment variables to values. "
|
||||||
"Returns the exit status of the program.")
|
"Returns the exit status of the program.")
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue