gpt4 book ai didi

python - Matlab 立即返回退出代码

转载 作者:太空狗 更新时间:2023-10-30 03:02:05 26 4
gpt4 key购买 nike

我正在使用 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.exebin\win32\matlab.exe(或 bin\win64\matlab.exe)。前者只是后者的包装,几乎可以立即退出。

您可以直接调用 bin\win32\matlab.exe 或使用 -wait option在调用 bin\matlab.exe 时。

关于python - Matlab 立即返回退出代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23130514/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com