gpt4 book ai didi

python - 从命令行运行 matlab 脚本后如何退出?

转载 作者:太空宇宙 更新时间:2023-11-03 13:47:39 25 4
gpt4 key购买 nike

这是我的python代码

DosCmd = 'matlab -wait -automation -nosplash -r "run \'' + to_run + "'\""
os.system(DosCmd)
curve_file = open('curve/'+str(index)+'.curve','r')

我在 python 脚本中运行一个 .m 文件,它工作正常但在执行 .m 文件后,它卡在 os.system(DosCmd) 中。为了让 python 运行下面的代码,我必须关闭这个窗口:

enter image description here

由于这部​​分代码是在循环中,真的很困扰我。我在网上看到有人说matlab在执行完.m文件后可以自动退出,我的就是不会。有人能告诉我我做错了什么或者我该怎么办吗?谢谢!

最佳答案

将对 exit 的调用添加到您执行的 MATLAB 代码中。

DosCmd = 'matlab -wait -automation -nosplash -r "run \'' + to_run + "', exit\""

你的引用看起来有点靠不住,但你只需要添加 , exit 到你在 -r 参数中传递的命令的末尾。

顺便说一下,使用 subprocess 会容易很多,这样你就可以让 subprocess 为你做报价。

subprocess.check_call(['matlab', '-wait', '-automation', '-nosplash', 
'-r', 'run \' + to_run + \', exit'])

关于python - 从命令行运行 matlab 脚本后如何退出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16234665/

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