Catch Matblab exception from Python

242 views Asked by At

From python script I call a Matlab (v2011B) function using 'subprocess.Popen'. Here is the code from python:

command = "matlab -nodisplay -nosplash -r -wait \"MyMatlabFunction(\'%s\',\'%s\'), exit\"" % (var1, var2)
args = shlex.split(command)
process = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=pathScripts, shell=False)
stdout, stderr= procesoMatlab.communicate()
print stderr

On my Matlab function I have a try-catch block like this:

try
    do myStuff
catch err
    fprintf(2, getReport(err))
end

The point is that when I get an exception on Matlab, the python subprocess module doesn´t receive any value on 'stderr' as it should.

How can I catch the Matlab exception/error in my python script?

0

There are 0 answers