473,241 Members | 1,729 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,241 software developers and data experts.

Determine whether program was started by clicking icon or commandline

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
Nov 29 '07 #1
4 1722
On Nov 29, 9:51 am, Benjamin Hell <bh...@spamfence.netwrote:
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
Nov 29 '07 #2
On Nov 28, 10:51 pm, Benjamin Hell <bh...@spamfence.netwrote:
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.

Nov 29 '07 #3
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
Nov 29 '07 #4
Roger Miller wrote:
On Nov 28, 10:51 pm, Benjamin Hell <bh...@spamfence.netwrote:
>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
Nov 30 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Ross Presser | last post by:
OK, I've been researching this problem and can't find a definitive answer yet. The situation is one that seems to have come up a few times to different folks. I am writing an application that...
4
by: esmith2112 | last post by:
Having a bear of a time trying to implement replication under 8.2 environment. I've created all of the control structures on both source and target database and can actually see data being staged...
6
by: Chris | last post by:
I have been learning C and want to write a program and need someone to point me in the write direction. I want to write a program to store all my webpage bookmarks in possibly one file. I want it...
3
by: Marco Martin | last post by:
Good Day Group, I'm trying to make my application open and run some code when a user clicks on a file with an associated extension. This is *my* understanding of what actually happens, please...
4
by: Tom | last post by:
How can one determine if a .NET program is running in the developer IDE or running stand-alone? I am sure I saw something somewhere but I don't remember where or what. Thanks! Tom
2
by: James MA | last post by:
I'm writing a program to handle multiple tasks in a single batch, which may take few minutes to complete all tasks. To reduce the impact to user, no windows form will be displayed, instead I have...
3
by: enzoJava | last post by:
Hii, i was wondering if there is a way to run a java program by just double clicking on an icon i have a program that i want to run on an old PC, and i dont want to download a compiler, just need to...
9
by: jvdb | last post by:
Hi all, I've created a program that receives files and opens the corresponding program (for example adobe acrobat). However, when started, i would like to see nothing of the running program. I...
2
by: gsander | last post by:
We have a W2K / Access2K environment where recent maintenance has prevented the /X commandline switch from starting macro's. We have several "batch" processes that run at night using the task...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.