python 3.6.8
import os
import sys
import subprocess
from subprocess import PIPE
argvs=sys.argv[1:]
print(argvs)
print("test.py turns eachturntimes firstthreshold")
truns=int(argvs[0])
eachTimes=int(argvs[1])
threshold=int(argvs[2])
path=os.getcwd()+"/main"
i = 0
totalVal=0
totaltimes=truns
while i < truns:
pipe = subprocess.Popen([path, str(eachTimes), str(threshold)], stdout=PIPE, bufsize=1)
sub=0
normal=1
file = open(str(i) + ".txt", "w+")
print("i times: " + str(i), flush=True)
for info in iter(pipe.stdout.readline, b''):
out=info.decode('utf-8')
arr=out.split(" ")
times = float(arr[1])
val = float(arr[3])
if val > threshold and sub == 0:
pipe.kill()
normal=0
print("execpt " + out, flush=True)
file.write(out)
sub=sub+1
if (times >= eachTimes):
print("val " + str(val), flush=True);
totalVal = totalVal + val
pipe.kill()
file.close()
if normal:
i=i+1
avg=totalVal/truns
print("avg is " + str(float(avg)))
网友评论