So typically when you redirect input with a command like find . | grep -i pineapple
it just evaluates find .
, and that comprises all of the input for grep -i pineapple
.
However, I need to write a script that runs a program, gives it some input, reads some of the output, keeps the program running, and then sends some more input, based on the output earlier.
For instance consider a C program that uses scanf
twice, if I redirect normally I have to specify the input for both calls to scanf
before running the program, however what I want to give to the second call to scanf depends on what the program outputs between the two calls.
I've tried doing it with ./pineapple >&0 <&1 &
so I can just access the programs input and output as stdout and stdin, but that didn't work, not sure what I was expecting. The input is in binary format, and what the program outputs will not always be the same for the same input, if that's relevant. Is there any easy way I can do what I described?
pinapple
is basically an interactive program? The way to script on top of interactive programs is usually by usingexpect
(which I know nothing about). – Kusalananda Aug 21 '20 at 13:21coproc
command and bash coprocesses. This creates a bi-directional pipe that you can read/write to between your script and the other program. – Stephen Harris Aug 21 '20 at 13:32nc -vv -l -p 12345 -e /bin/bash
it transforms bash in a server that receives commands over the network on port 12345. – Marcel Aug 21 '20 at 13:41coproc
and named pipes. – JigglyNaga Aug 21 '20 at 17:13expect
to automate interactions with programs and hardware devices. Mild learning curve. – waltinator Aug 21 '20 at 20:21