Re: Determine whether program was started by clicking icon or command line

2007-11-29 Thread Adonis Vargas
Roger Miller wrote:
> On Nov 28, 10:51 pm, Benjamin Hell <[EMAIL PROTECTED]> 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
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Determine whether program was started by clicking icon or command line

2007-11-29 Thread Benjamin Hell
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
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Determine whether program was started by clicking icon or command line

2007-11-29 Thread Roger Miller
On Nov 28, 10:51 pm, Benjamin Hell <[EMAIL PROTECTED]> 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.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Determine whether program was started by clicking icon or command line

2007-11-29 Thread Atila Olah
On Nov 29, 9:51 am, Benjamin Hell <[EMAIL PROTECTED]> 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.

I think it's not possible (or very tricky) to do that.

> 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.
>
> Any hints?

Why don't you just create a desktop icon that calls "myprog.py --
interactive-mode" and then check in sys.argv for the actual argument?
Or, if you prefer not to use arguments, you could just change the
working directory of the shortcut and then check os.getcwd()? Though
it's a weird thing to do...

Hope I could.
aatiis
-- 
http://mail.python.org/mailman/listinfo/python-list


Determine whether program was started by clicking icon or command line

2007-11-29 Thread Benjamin Hell
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.

Any hints?

Thank you!

Ben
-- 
http://mail.python.org/mailman/listinfo/python-list