I used the library code os to open a google window.
import os
os.startfile("C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Google Chrome")
I would like to add time.sleep and then close that window, but I have no idea how to do it.
I used the library code os to open a google window.
import os
os.startfile("C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Google Chrome")
I would like to add time.sleep and then close that window, but I have no idea how to do it.
os.startfile()
is a specific routine for windows, basically invokes the associated program to the file that you pass by parameter, it means that if you do os.startfile(archivo.txt)
it is most likely that you open the notepad
or some program that you have registered for that extension. In addition you will not return any process identifier that will then serve to kill the application.
In your example you are wanting to open an executable program so the best way would be to use subprocess , in the following way:
import subprocess
proc = subprocess.Popen("C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Google Chrome", shell=False)
Popen
returns a <subprocess.Popen>
object that will allow you to finish the process, using the method terminate()
in the following way:
proc.terminate()