从Python捕获Matblab异常

从Python捕获Matblab异常,python,matlab,subprocess,popen,Python,Matlab,Subprocess,Popen,从python脚本中,我使用“subprocess.Popen”调用一个Matlab(v2011B)函数。以下是python中的代码: command = "matlab -nodisplay -nosplash -r -wait \"MyMatlabFunction(\'%s\',\'%s\'), exit\"" % (var1, var2) args = shlex.split(command) process = subprocess.Popen(args, stdout=subproce

从python脚本中,我使用“subprocess.Popen”调用一个Matlab(v2011B)函数。以下是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
在我的Matlab函数中,我有一个try-catch块,如下所示:

try
    do myStuff
catch err
    fprintf(2, getReport(err))
end
关键是,当我在Matlab上得到一个异常时,python子流程模块在“stderr”上没有收到它应该收到的任何值


如何在python脚本中捕捉Matlab异常/错误?

您是否尝试过:是的,Dan,我读过这篇文章,但在我的情况下不起作用。Stderr和stdout返回总是空的。看起来fprintf不在stderr和stdout的同一管道上写入。不管怎样,谢谢你尝试过这个:是的,丹,我读过这篇文章,但对我来说不起作用。Stderr和stdout返回总是空的。看起来fprintf不在stderr和stdout的同一管道上写入。无论如何谢谢你