【发布时间】:2021-05-31 17:47:19
【问题描述】:
我开发了以下循环,用于使用循环运行具有不同降雨集合的模型。除了我的.bat文件的执行过程之外,脚本运行正常。
import os
import glob
import subprocess
ws = (r'C:\Users\Wahid Hussainzada\Desktop\Takahashi_2018_9_test')
os.chdir(ws)
myFile = glob.glob('*.txt')
myModel = glob.glob('2cdrmv3.bat')
for i in myFile:
if i.startswith('rain'):
print(i)
myBat = open(ws+'\wahid.bat','w+')
myBat.write('cdrmv3.exe param1.txt param2.txt param3.txt param4.txt bsndir.txt slope.txt length.txt order.txt takahashi_landuse.txt takahashi_acc.txt 0 # 1 takahashi_thiessen.txt 13 '+str(i) +' 0 1 out_'+str(i) +' 0 outgrid\outa2 outgrid\outb')
myBat.close()
subprocess.call('C:\Users\Wahid Hussainzada\Desktop\Takahashi_2018_9_test\wahid.bat')
else:
print("Other txt files than rain files")
【问题讨论】:
-
查看
subprocess.run(docs.python.org/3/library/…) 的文档。如果您指定shell=True,该命令将使用 shell 运行。但是如果您指定 shell=True (docs.python.org/3/library/…),则需要注意安全注意事项
标签: python loops batch-file spyder modeling