Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Matlab立即返回退出代码_Python_Matlab_Subprocess_Exit Code - Fatal编程技术网

Python Matlab立即返回退出代码

Python Matlab立即返回退出代码,python,matlab,subprocess,exit-code,Python,Matlab,Subprocess,Exit Code,我正在用python创建各种matlab.m文件,然后使用子流程运行它们。文件完成后,我想删除它们: command = ['C:\\MatlabR2012b\\bin\\matlab.exe', '-nodesktop', '-nosplash', '-r', 'mfile'] matlab = subprocess.Popen(command) # launch matlab with m file matlab.wait() # wait for matlab to

我正在用python创建各种matlab.m文件,然后使用子流程运行它们。文件完成后,我想删除它们:

    command = ['C:\\MatlabR2012b\\bin\\matlab.exe', '-nodesktop', '-nosplash', '-r', 'mfile']
    matlab = subprocess.Popen(command) # launch matlab with m file
    matlab.wait() # wait for matlab to finish before deleting .m file
    print "delete"
    os.remove(self.filename)

问题是matlab.wait()从不等待,因为matlab会立即返回退出代码0。是否有其他方法检查matlab是否已完成?

在Windows上,有
bin\matlab.exe
bin\win32\matlab.exe
(或
bin\win64\matlab.exe
)。前者只是后者的一个包装,几乎可以立即退出


您可以直接调用
bin\win32\matlab.exe
,也可以在调用
bin\matlab.exe
时使用我永远也找不到那个。@Pphoenix:很高兴我能帮助你!不相关:您可以使用
子流程。检查调用(命令)
而不是
Popen(..)。wait()
。如果
命令
以非零状态退出,则前者也会引发异常。