Determine whether program was started by clicking icon or command line
Benjamin Hell
bhell at spamfence.net
Thu Nov 29 16:06:18 EST 2007
Roger Miller wrote:
>> 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.
>
> 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.
Nice idea, but this...
import sys
print sys.stdin.fileno()
raw_input("Press any key to exit")
...
always prints "0" in my case ("DOS", double click in Windows
Explorer, Cygwin shell).
Thanks anyways!
Ben
More information about the Python-list
mailing list