Add SHELL_EXIT_CODE to psql - Mailing list pgsql-hackers

From Corey Huinker
Subject Add SHELL_EXIT_CODE to psql
Date
Msg-id CADkLM=cWao2x2f+UDw15W1JkVFr_bsxfstw=NGea7r9m4j-7rQ@mail.gmail.com
Whole thread Raw
Responses Re: Add SHELL_EXIT_CODE to psql
List pgsql-hackers

Over in https://www.postgresql.org/message-id/eaf326ad693e74eba068f33a7f518039@oss.nttdata.com Justin Pryzby suggested that psql might need the ability to capture the shell exit code.

This is a POC patch that does that, but doesn't touch on the ON_ERROR_STOP stuff.

I've added some very rudimentary tests, but haven't touched the documentation, because I strongly suspect that someone will suggest a better name for the variable.

But basically, it works like this

-- SHELL_EXIT_CODE is undefined
\echo :SHELL_EXIT_CODE
:SHELL_EXIT_CODE
-- bad \!
\! borp
sh: line 1: borp: command not found
\echo :SHELL_EXIT_CODE
32512
-- bad backtick
\set var `borp`
sh: line 1: borp: command not found
\echo :SHELL_EXIT_CODE
127
-- good \!
\! true
\echo :SHELL_EXIT_CODE
0
-- play with exit codes
\! exit 4
\echo :SHELL_EXIT_CODE
1024
\set var `exit 3`
\echo :SHELL_EXIT_CODE
3


Feedback welcome.
Attachment

pgsql-hackers by date:

Previous
From: Dilip Kumar
Date:
Subject: Re: Moving forward with TDE
Next
From: Simon Riggs
Date:
Subject: Re: Allow single table VACUUM in transaction block