Reputation: 615
I'm trying to write a script that will run a program, wait for a certain output from the program, then continue execution (and leave the program running.) My current code doesn't seem to ever output anything, sed never returns true. This echos "Peerflix started" but that's it.
exec 3< <(peerflix $1 -p 8888)
echo "Peerflix started."
sed '/server$/q' <&3
echo 'Matched'
Upvotes: 3
Views: 2420
Reputation: 12603
Use pipes!
Use mkfifo
to created a pipe and stream the program's output to it in a non-blocking command. Then use your blocking sed
to read from that pipe.
Something like(did not test - I don't have peerflix
):
mkfifo myfifo
peerflix $1 -p 8888 > myfifo &
echo "Peerflix started."
sed '/server$/q' myfifo
echo 'Matched'
rm myfifo
Upvotes: 1