diff options
Diffstat (limited to 'src/bin/psql/command.c')
-rw-r--r-- | src/bin/psql/command.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 61ec049f054..d7731234b63 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -5041,6 +5041,21 @@ do_shell(const char *command) else result = system(command); + if (result == 0) + { + SetVariable(pset.vars, "SHELL_EXIT_CODE", "0"); + SetVariable(pset.vars, "SHELL_ERROR", "false"); + } + else + { + int exit_code = wait_result_to_exit_code(result); + char buf[32]; + + snprintf(buf, sizeof(buf), "%d", exit_code); + SetVariable(pset.vars, "SHELL_EXIT_CODE", buf); + SetVariable(pset.vars, "SHELL_ERROR", "true"); + } + if (result == 127 || result == -1) { pg_log_error("\\!: failed"); |