So I have a Linux program that runs in a while(true) loop, which waits for user input, process it and print result to stdout.
I want to write a shell script that open this program, feed it lines from a txt file, one line at a time and save the program output for each line to a file.
So I want to know if there is any command for:
– open a program
– send text to a process
– receive output from that program
Many thanks.
It sounds like you want something like this:
This will run a new instance of
progfor each line. The line will be the standard input ofprogand the output will be put in the variableanswerfor your script to further process.Some people object to the “cat file |” as this creates a process where you don’t really need one. You can also use file redirection by putting it after the
done: