Re: Add SHELL_EXIT_CODE to psql

Поиск
Список
Период
Сортировка
От Maxim Orlov
Тема Re: Add SHELL_EXIT_CODE to psql
Дата
Msg-id CACG=ezYNoeAbSHbLDuEHH7SkKnnF0AF4N5kGda8=G9QRBvfL0A@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Add SHELL_EXIT_CODE to psql  (Corey Huinker <corey.huinker@gmail.com>)
Ответы Re: Add SHELL_EXIT_CODE to psql  (Corey Huinker <corey.huinker@gmail.com>)
Список pgsql-hackers
Hi!

The patch is implementing what is declared to do. Shell return code is now accessible is psql var.
Overall code is in a good condition. Applies with no errors on master.
Unfortunately, regression tests are failing on the macOS due to the different shell output.

@@ -1308,13 +1308,13 @@
 deallocate q;
 -- test SHELL_EXIT_CODE
 \! nosuchcommand
-sh: line 1: nosuchcommand: command not found
+sh: nosuchcommand: command not found
 \echo :SHELL_EXIT_CODE
 127
 \set nosuchvar `nosuchcommand`
-sh: line 1: nosuchcommand: command not found
+sh: nosuchcommand: command not found
 \! nosuchcommand
-sh: line 1: nosuchcommand: command not found
+sh: nosuchcommand: command not found
 \echo :SHELL_EXIT_CODE
 127

Since we do not want to test shell output in these cases, but only return code,
what about using this kind of commands?
postgres=# \! true > /dev/null 2>&1
postgres=# \echo :SHELL_EXIT_CODE
0
postgres=# \! false > /dev/null 2>&1
postgres=# \echo :SHELL_EXIT_CODE
1
postgres=# \! nosuchcommand > /dev/null 2>&1
postgres=# \echo :SHELL_EXIT_CODE
127

It is better to use spaces around "=".
+               if (WIFEXITED(exit_code))
+                       exit_code=WEXITSTATUS(exit_code);
+               else if(WIFSIGNALED(exit_code))
+                       exit_code=WTERMSIG(exit_code);
+               else if(WIFSTOPPED(exit_code))
+                       exit_code=WSTOPSIG(exit_code);

--
Best regards,
Maxim Orlov.

В списке pgsql-hackers по дате отправления:

Предыдущее
От: Peter Eisentraut
Дата:
Сообщение: Add BufFileRead variants with short read and EOF detection
Следующее
От: Michail Nikolaev
Дата:
Сообщение: Re: Data loss on logical replication, 12.12 to 14.5, ALTER SUBSCRIPTION