diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2023-04-06 17:33:38 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2023-04-06 17:33:38 -0400 |
commit | 31ae2aa9d2c200a0d7d3283d749669a408ec7b65 (patch) | |
tree | c8781c1909b5df38ed2c86bf334c1ae856f4a33c /src/bin/psql/command.c | |
parent | 029dea882a7aa34f46732473eed7c917505e6481 (diff) |
psql: set SHELL_ERROR and SHELL_EXIT_CODE in more places.
Make the \g, \o, \w, and \copy commands set these variables
when closing a pipe. We missed doing this in commit b0d8f2d98,
but it seems like a good idea.
There are some remaining places in psql that intentionally don't
update these variables after running a child program:
* pager invocations
* backtick evaluation within a prompt
* \e (edit query buffer)
Corey Huinker and Tom Lane
Discussion: https://postgr.es/m/CADkLM=eSKwRGF-rnRqhtBORRtL49QsjcVUCa-kLxKTqxypsakw@mail.gmail.com
Diffstat (limited to 'src/bin/psql/command.c')
-rw-r--r-- | src/bin/psql/command.c | 16 |
1 files changed, 2 insertions, 14 deletions
diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index e8f583cac22..97f7d972202 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -2734,6 +2734,7 @@ exec_command_write(PsqlScanState scan_state, bool active_branch, pg_log_error("%s: %s", fname, wait_result_to_str(result)); status = PSQL_CMD_ERROR; } + SetShellResultVariables(result); } else { @@ -5119,20 +5120,7 @@ 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"); - } + SetShellResultVariables(result); if (result == 127 || result == -1) { |