mercredi 30 mai 2018

Python cmd script hanging when trying to loop

I'm trying to make a python script to run a batch file multiple times with different configurations one after the other. The problem I'm having is that I'm trying to find a wait for it to wait for the run to finish and then run another one, but the cmd hangs and doesn't let the second argument to be written in the cmd. It does not do that when just using the cmd to run the batch file manually. So don't really understand what the problem is. I'm really new to Python so suggestions how to make this script better is welcome:

import subprocess

# open commandline
subprocess.Popen([r"cmd"])

# Run every test 5 times.
# Wait for a single run to finish before running another one

for x in xrange(5):
    subprocess.Popen([r"batchfile.bat", "arg", "arg", "arg", "arg"])
    subprocess.Popen.wait(timeout=None)

for x in xrange(5):
    subprocess.Popen([r"batchfile.bat", "arg", "arg", "arg", "arg"])
    subprocess.Popen.wait(timeout=None)

Aucun commentaire:

Enregistrer un commentaire