I'm working on an optimization and for that I need to link a matlab code into a linux program and keep monitoring the outputs. I'd done this link using this sh below, however it wasn't working well, since I couldn't keep track of more than one 'expression'.
#!/bin/bash
../program inputfile &> OutputFile.dat &
tail -f OutputFile.dat | sed -n '/NaN/q;/STOP/q'
killall program
I've asked for help here, and I got a good solution. The solution solved partially the problem. Running the program on the prompt it was possible to keep track on those expressions and kill the program when needed. The solution given was:
#!/bin/bash
( stdbuf -o 0 -e 0 ../program inputfile & ) &> OutputFile.dat
sed -n '/NaN/q;/STOP/q' <(tail -f OutputFile.dat)
killall program
When I implemented on the matlab, and did the 'linkage' the code didn't responded well. After a few minutes running, the matlab got stuck, I couldn't get any answer from the terminal. When looked manually on the outputs of my program I realized that there were no problems on the program, and the outputs was normally being written.
I can't solve this problem. I don't have a lot of experience on sh. I've searched for answers, but I couldn't find any. Alternative suggestions to achieve the same thing are also welcome.
Thanks in advance