mirror of
https://github.com/postgres/postgres.git
synced 2025-06-30 21:42:05 +03:00
Add SHELL_ERROR and SHELL_EXIT_CODE magic variables to psql.
These are set after a \! command or a backtick substitution. SHELL_ERROR is just "true" for error (nonzero exit status) or "false" for success, while SHELL_EXIT_CODE records the actual exit status following standard shell/system(3) conventions. Corey Huinker, reviewed by Maxim Orlov and myself Discussion: https://postgr.es/m/CADkLM=cWao2x2f+UDw15W1JkVFr_bsxfstw=NGea7r9m4j-7rQ@mail.gmail.com
This commit is contained in:
@ -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");
|
||||
|
Reference in New Issue
Block a user