ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> activepython
activepython
Re: detecting launching from explorer
by Trent Mick other posts by this author
Feb 16 2007 9:36AM messages near this date
view in the new Beta List Site
detecting launching from explorer | Cannot find Python executable
Scott Roland wrote:
>  I have a python script that can either be launched from cygwin, a DOS
>  cmd.exe shell, or by double clicking on the icon in a Windows Explorer
>  window.
>  
>  When it is launched by double clicking from a Windows Explorer window it
>  opens up a new cmd.exe window to run the program and the window closes
>  when it is done. I would like to be able pause at the end of execution
>  in this new window and wait for a key press, so that the user can see
>  what is in the window before it closes. I can check platform.system, and
>  make sure that I don't do this in cygwin, but how can I not make the
>  program pause for a key press when the script was launched from the
>  command line?
>  
>  At the moment I have created a shortcut that passes an argument to the
>  script, but I was hoping for a solution that doesn't involve editing the
>  shortcut.

The only hints I can see using to differentiate (and they aren't perfect) are:

- When run from the shell os.environ will have changes that have been made to 
that shell's environment (if any).
- When run from explorer, the path to the script (i.e. sys.argv[0]) will 
always be an absolute path. However, that isn't perfect because when run from 
the shell it *might* be an absolute path.

When you run via explorer, what is actually being run is the "open" verb of 
your .py file association:

C:\> assoc.py
.py=Python.File

C:\> ftype Python.File
Python.File="C:\Python24\python.exe" "%1" %*


If you only need this for your machine you could try to put some hint in the 
Python.File action.


Trent


-- 
Trent Mick
trentm@[...].com
_______________________________________________
ActivePython mailing list
ActivePython@[...].com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Other options: http://listserv.ActiveState.com/mailman/listinfo/ActivePython
Thread:
Scott Roland
Trent Mick

Privacy Policy | Email Opt-out | Feedback | Syndication
© 2004 ActiveState, a division of Sophos All rights reserved