Is the Matlab process running with a specific exit code if it finds something? Just use the exit code in this case. Or just start the Matlab process, write a file with its output, and then you can create an observer in python to detect changes in the file.
The easiest way is to force Matlab to also create an empty file (in addition to the output file itself) when it finds something. Then you can simply check if the file exists at regular intervals using os.path.exists () and time.sleep :
import os import time path='/path/to/file/created/by/matlab' while not os.path.exists(path): print("Matlab output file still not present. Waiting for 1 s and retrying...") time.sleep(1) print("Matlab process generated output. Now I can do what I want to do")
If you cannot change the matlab script, you can take a look at mlabwrap , which is a module through which you can call matlab through python. Also see this answer .
source share