0

I want to write a python program that would open an application and wait till it's closed and at last prints when it was closed. I wrote the below code but it prints the time right after it is opened.

I used os.startfile(path_to_application) to run the file, but the online documentation says that this function doesn't have the option to wait for the application to close, and no way to retrieve the application's exit status.

Question: Is there a function that I can use to know when the application is closed?

Code:

import time, os

start = time.time()
os.startfile(path_to_application)
end = time.time()

print end - start, "seconds"
1
  • I believe the os version that waits is os.system(), equivalent to Mike Müllers answer.
    – Anton vBR
    Commented Jul 27, 2017 at 16:41

1 Answer 1

1

Use subprocess.call():

import subprocess

subprocess.call(path_to_application)

Run command with arguments. Wait for command to complete or timeout, then return the returncode attribute.

Not the answer you're looking for? Browse other questions tagged or ask your own question.