bug-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: no exit status available when a command doesn't exist or fails in pi


From: Ed Morton
Subject: Re: no exit status available when a command doesn't exist or fails in pipe to grep
Date: Mon, 6 Sep 2021 13:14:59 -0500
User-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0

On 9/6/2021 12:47 PM, Neil R. Ormos wrote:
ED MORTON wrote:

I was just trying to write a function that would
do the same for awk that command substitution
does for shell, i.e. run some command and use
it's output in some context, e.g.:
[...]
but I need to know the exit status if the
pipeline failed to be able to do that robustly.
I thought I'd have that exit status in the
result of the pipeline:
[...]
or in ERRNO:
[...]
but clearly I don't. Should `ERRNO` be populated
in that situation? If not, is there any other
way for me to get the exit status of the command
that I ran to pipe it's output to getline, like
I'd have it in the return from system() (which
obviously I can't use for this task):
Use the value returned by close().

The "Closing Input and Output Redirections"
section of the manual says:

| In gawk, starting with version 4.2, when closing
| a pipe or coprocess (input or output), the
| return value is the exit status of the command,
| as described in Table 5.1.29


Perfect:

   $ awk 'BEGIN{cmd="garbage"; (cmd | getline); print close(cmd)}'
   sh: garbage: command not found
   127

I know this is a gawk mailing list but I don't suppose you know of a POSIX equivalent?

   $ awk --posix 'BEGIN{cmd="garbage"; (cmd | getline); print close(cmd)}'
   sh: garbage: command not found
   0

Thanks!

    Ed.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]