Determine whether program was started by clicking icon or command line

Adonis Vargas adonisv at REMOVETHISearthlink.net
Thu Nov 29 21:54:26 EST 2007


Roger Miller wrote:
> On Nov 28, 10:51 pm, Benjamin Hell <bh... at spamfence.net> wrote:
>> Hi!
>>
>> I wonder whether there might be a way to find out how a Python
>> program was started (in my case in Windows): By double clicking the
>> file or by calling it on the "DOS" command line prompt.
>>
>> Background: I would like to have the program run in an "interactive
>> mode" if double clicked, and silently in a "batch mode" when started
>> otherwise.
> 
> I'm not sure whether this applies to your situation, but often
> programs
> started by clicking an icon are run by pythonw, but when started from
> the command line are run by python. If this is the case
> sys.stdin.fileno()
> will return -1 in the former case and 0 in the latter.
> 

No, when it gets executed by pythonw the application has an extension of 
.pyw and .py files are run by the regular python executable. This the 
default behavior, unless for some odd reason you modified this through 
the registry or through explorer to do otherwise.

Adonis Vargas



More information about the Python-list mailing list