3

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'

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

2 Comments

This will block at peerflix $1 -p 8888 > myfifo unless you explicitly run it in the background. The OP's exec 3< <(peerflix $1 -p 8888) process substitution is however, non-blocking
weirdly enough, it's not working at all. I've realized that I need to be checking stderr instead of stdout, but my solution of gist.github.com/anonymous/81d10eb2cc228a7c90fd isn't working at all. (external link cause comments don't have newlines)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.