PetGriffin
PetGriffin

Reputation: 545

Python not waiting for subprocess to finish?

I am trying to use Python 3 to run a windows program a number of times with different inputs. To run the program from the command line I use

C:\prog -v input_file 

My python equivalent is

args = ['prog','-v', input_file]
subprocess.call(args)

I need to wait for prog to finish before post-processing the results but something is not quite right. For example, if I run the program 3 times and write a summary of the results to file I would expect to see this

run 1   summary of run 1
run 2   summary of run 2
run 3   summary of run 3

but this is what I actually get

run 2   summary of run 2
run 3   summary of run 3
run 3   summary of run 3

There are a whole bunch of WMIC processes running after I finish the Python script, so maybe these have got something to do with the problem? Basically, the Python script seems to be getting ahead of itself and doing some of the post-processing too early. All suggestions gratefully received - thanks!

Upvotes: 0

Views: 165

Answers (1)

PetGriffin
PetGriffin

Reputation: 545

Sorry - had a closer look at the code and there was an issue with indenting which affected program flow and thus the way in which the data was written to file. Still having issues with the WMIC files but will close this issue and open a separate one about the WMIC files

Upvotes: 1

Related Questions