我有一个用python脚本运行的C程序,输出是一个包含随机值(以某种方式)的文本文件。但是,当我在一个循环中多次运行程序时,每次都会得到相同的输出文本文件(或者100个中有2个不同的文本文件)
import subprocess
import time
start = time.time()
ntrial = input("How many trials? ")
for i in range(int(ntrial)):
cmd = ["/Users/stordd/Desktop/StageI2M/C/forestenostre/grezza_foresta", "-w",
"/Users/stordd/Desktop/StageI2M/Leiden/text_file/USA.txt", "-m", "5", "-e", "-0"]
# Open/Create the output file
outFile = open("/Users/stordd/Desktop/StageI2M/Leiden/k5/{}.txt".format(i), 'ab')
result = subprocess.Popen(cmd, stdout=subprocess.PIPE)
out = result.stdout.read()
outFile.write(out)
outFile.close()
end = time.time()
print(end - start)