[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: |
Neil R. Ormos |
Subject: |
Re: no exit status available when a command doesn't exist or fails in pipe to grep |
Date: |
Mon, 6 Sep 2021 12:47:20 -0500 (CDT) |
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