This only works on Windows with shell=True
because the default program for the extension is used to open the given file, it's the equivalent of using cmd /c Path\To\File
The problem is that
while sub.poll():
pass
does not what you want. sub.poll()
returns None
while the program is running, and the exit code of the program when it has finished. If the program were to terminate with an exit code other then 0 before reaching this loop, then it would just keep looping and consuming CPU. If the program is still running or has completed successfully then the loop is not entered at all.
Checking wheather a process is still runing using poll()
should be done by checking sub.poll() is None
, or better use sub.wait()
.
Some programs however allow only one active instance, if you try to start a second instance it will instead open the file in the open window and exit immediately. In that case there is no easy way to know wheather the file is still open in the application. So the behaviour also depends on the registered program.