'Matlab System Command Script stops

I am starting a python-script out of Matlab using the system()-command.

I would to check in a while loop if the script is still running and do something else while running. If it is not running anymore, I would like to break the while-loop and continue my Matlab script. However, it seems that the while loop starts when I already closed the python-script and not while the script is still running:

    checkpython = 'pgrep python';
    
    system('unset LD_LIBRARY_PATH;python3 MyPythonScript.py')
    [status1,~] = system(checkpython);

    while status1==0 
    [status,~] = system(checkpython);
    
    %%% Doing something else here %%%
    
        if status == 1
            disp('Python closed')
           break
        end
    end 

How could I check while the python script is running if it is still running and do something else in that while-loop?

Thanks for your advice!

Best, Sophie



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source