473,394 Members | 1,841 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,394 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 1730
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.