3

I'm creating a script in python that will open a program then python will wait for that program to close itself before continuing to the next code. Here is my script:

Import subprocess as sp
sp.Popen([r'C:/Folder/folder/a.exe'])
??????
????????
print("test")

The question marks are the things that I don't know.

2 Answers 2

5

Try subprocess.call instead of Popen. It waits for the command to complete.

import subprocess
subprocess.call('a.exe')
print("test")

For reference.

1
  • Thank you, I marked this answered becaused it work, thou I put the exact location of the exe file rather than just regular a.exe Jul 24, 2019 at 4:01
5

@Legate77's answer is correct, but for versions > 3.5, subprocess.run is preferred:

import subprocess
subprocess.run(['./a.out', 'arg1', 'arg2'])
print('done')

Documentation is on the same page

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .