Is there any way to capture shell output (in a psql variable) and/or the exit code of running a shell command from inside psql using \!? The documentation provides no details.
3 Answers
You can use \o <filename> option to specify the output file or use COPY command to solve your problem.
6 Comments
Sim
I'm not sure how
\o helps. If I am running a shell command, I can always redirect its output to a file. Also not sure how COPY helps. I'm not trying to load data.Dzmitry Savinkou
well, I guess it depends what you are trying to achieve, for bulk ddl updates I used
\o a lot. I guess it's not your case.Dzmitry Savinkou
this might be what you are looking for
Sim
The SO question you point to is about capturing SQL output from psql. I want to capture shell output and exit code in psql.
Sim
I can capture the shell exit status of
psql but I see no documentation for how to capture the exit status of whatever is run via \!. Do you? |