bug-gawk
[Top][All Lists]
Advanced

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

Re: How to get the exit code of `command | getline [var]`?


From: Peng Yu
Subject: Re: How to get the exit code of `command | getline [var]`?
Date: Sat, 16 May 2020 21:18:11 -0500

But the problem comes for the following usage.

while (cmd | getline x) {
...
}


This works. But it is not clear how to read from a pipe using a while loop.

while(getline x) {
...
}

On 5/16/20, david kerns <address@hidden> wrote:
> awk -v tmpfile="$(mktemp -u)" -e 'BEGIN { cmd = "cat " tmpfile; cmd |
> getline x; exit_code = close(cmd); print x, exit_code }'
>
> On Sat, May 16, 2020 at 3:59 PM Peng Yu <address@hidden> wrote:
>
>> Hi,
>>
>> There is an error below. But I can not get the error code. Is there a
>> way to get the error code? Thanks.
>>
>> $ awk -v tmpfile="$(mktemp -u)" -e 'BEGIN { exit_code = "cat " tmpfile
>> | getline x; print exit_code; print x }'
>> cat: /tmp/mktemp/tmp.USzT4D7yJ3: No such file or directory
>> 0
>>
>> --
>> Regards,
>> Peng
>>
>>
>


-- 
Regards,
Peng



reply via email to

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