Reputation: 1163
I have a program which reads from stdin and prints to stdout. I want to be able to redirect output to serve as an input for the program during its execution. I prefer not to use expect
. Below is an example script using fifo but it's flawed in some way which I am unable to understand.
mkfifo fifo
echo "Initial input" > fifo
cat fifo | ./my_program > fifo
rm -rf fifo
Upvotes: 0
Views: 64
Reputation: 123410
This fails because the echo
statement will wait forever for a reader to attach.
One alternative is:
mkfifo fifo
{ echo "Initial input"; cat fifo; } | ./my_program > fifo
It's up to ./my_program
to:
If the program fails to do any of the above, it will hang or deadlock. This is a problem with ./my_program
and not with the bash snippet.
Upvotes: 1