Matlab returns exit code immediately

狂风中的少年 提交于 2019-12-12 12:13:20

问题


I am creating various matlab .m-files with python and then run them using subprocess. When the files are finished I would like to delete them:

    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)

The problem is that matlab.wait() never waits, since matlab returns exit code 0 immediately. Is there another way to check if matlab has finished?


回答1:


On Windows, there is both bin\matlab.exe and bin\win32\matlab.exe (or bin\win64\matlab.exe). The former is just a wrapper around the latter and pretty much exits immediately.

You can either call bin\win32\matlab.exe directly or use the -wait option when calling bin\matlab.exe.



来源:https://stackoverflow.com/questions/23130514/matlab-returns-exit-code-immediately

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!