Backstory: I'm working with a piece of software that uses CMake for several build options. On my desktop build system when I execute a 'Processor Reset' command the program exits cleanly, but needs restarted with a different set of parameters. (The functionality works correctly on hardware, so I do not wish to modify the underlying source whatsoever.)
Question: My question is, how can I monitor the terminal output from the program, and upon seeing "Processor Reset Received", trigger a new instance of the program?
- My preferred answer would perform this in a shell script, but I'm open to other ideas.
- I do not wish for there to be any recursion.
Start the program with a Power-On Reset
(Program runs and prints output to terminal)
Send a Processor Reset Command
Program receives Processor Reset Command, prints relevant information, and terminates
Monitor program reads that the original program has terminates with a Processor Reset, and runs the program again with different flags.
Things I've tried
I have a partially working solution that... is interesting. It appears that there is some weird buffering going on which I've tried to disable, albeit unsuccessfully. But - it does successfully parse the program's terminal output and execute the Processor Reset flags when necessary (albeit once, as it is not in a loop.)
stdbuf -o0 -i0 -e0 sudo ./program -PO | tee /dev/tty | (grep "Processor Reset.") | (read && sudo ./program -PR)
- I need the code to not buffer large chunks of data (i.e. write smoothly as it produces output)
- It should be wrapped in a loop to allow multiple Processor Resets. (Any other reset should terminate the loop.)