os.startfile hanging onto the launched app, or my IDE?

Ian Kelly ian.g.kelly at gmail.com
Sun Jun 8 13:56:35 EDT 2014


On Fri, Jun 6, 2014 at 2:34 PM, Josh English <Joshua.R.English at gmail.com> wrote:
> I have been using os.startfile(filepath) to launch files I've created in Python, mostly Excel spreadsheets, text files, or PDFs.
>
> When I run my script from my IDE, the file opens as I expect. But if I go back to my script and re-run it, the external program (either Excel, Notepad, or Acrobat Reader) closes all windows and restarts the program. This can, unfortunately, close other files I am working on and thus I lose all my changes to those files.
>
> This is happening on Windows 7.
>
> I am not sure if it is Python (2.7.5) or my IDE (PyScripter 2.5.3).
>
> It seems like Python or the IDE is keeping track of things created by the os.startfile call, but the docs imply this doesn't happen.
>
> Is this a quirk of os.startfile? Is there a cleaner way to get Windows to open files without tying back to my program?

That sounds unusual.  Do you see the same behavior with the shell
"start" command?  My first guess would be that this is due to some
registry setting rather than Python, which pretty much just calls
ShellExcecute.



More information about the Python-list mailing list