Sample Header Ad - 728x90

Why does this gawk coprocess hang?

3 votes
1 answer
431 views
While having a go at https://unix.stackexchange.com/q/368234/70524 , I tried GNU awk's coprocess feature : gawk -F, -v cmd='date +"%Y-%m-%d %H:%M:%S" -f-' '{print $5 |& cmd; cmd |& getline d; $5 = d}1' foo This command hangs. I thought this might be because date is waiting to read the entire input, so I tried to close the sending half of the pipeline: gawk -F, -v cmd='date +"%Y-%m-%d %H:%M:%S" -f-' '{print $5 |& cmd; close(cmd, "to"); cmd |& getline d; $5 = d}1' foo This works (yes, I know I should set OFS=,, but for now...). However, date seems to have no problem processing input as it comes in. This gives the first line of output immediately: d='Thu Apr 27 2017 23:19:47 GMT+0700 (ICT)' (echo "$d"; sleep 1m; echo "$d") | date +"%Y-%m-%d %H:%M:%S" -f- What's going on?
Asked by muru (77471 rep)
May 31, 2017, 06:32 AM
Last activity: Jun 19, 2019, 03:15 PM