What makes this tricky is that waf
misbehaves by not exiting when the pipe breaks, and it spawns off a second process that we also have to get rid off:
tmp=$(mktemp)
cat <(./waf --run scratch/myfile & echo $! > "$tmp"; wait) | awk -f filter.awk;
pkill -P $(<$tmp)
kill $(<$tmp)
- We use
<(process substitution)
to runwaf
in the background and write its pid to a temp file. - We use
cat
as an intermediary to relay data from this process to awk, sincecat
will exit properly when the pipe is broken, allowing the pipeline to finish. - When the pipeline's done, we kill all processes that
waf
has spawned (by Parent PID) - Finally we kill
waf
itself.