Say I have a server writing stdout to a consumer
my server | upon 'some pattern' --exit=0
so basically when the consumer reads stdout, and sees a certain pattern it will exit. my question is - when it exits, how I clean up the pipeline and potentially make the server a background process?
Maybe this is just a better way to do it:
( my server &> $file ) &
while true; do
cat $file | upon 'some pattern' --exit=0
done
basically instead of sleep 5
seconds or what not, I am hoping to use a more evented approach, that guarantees the server is ready.
server
to/dev/null
when a pattern is seen by the right hand of the pipeline, I don't think that's possible, in a clean way. You can start the server in background and have the right hand transform itself in a lightweightcat
upon seeing the pattern. Eg:{ server & } | { sed /pattern/q; cat >/dev/null & }
. And there are hacks like this to force redirect file descriptors from a running process. – May 18 '19 at 17:37server > tmpfile & tail -f tmpfile | grep -m1 pattern
but then the server will keep writing totmpfile
and filling up your disk. – May 18 '19 at 19:16