473,221 Members | 1,887 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,221 software developers and data experts.

Is there a way to tell if a script has been run by Pythonw.exe instead of Python.exe?

In particular I want to know how to tell if reading and writing to the
console can occur.
Something like
sys.isConsolePresent()

Oct 18 '07 #1
5 1402
On Oct 19, 7:56 am, Metalone <j...@iteris.comwrote:
In particular I want to know how to tell if reading and writing to the
console can occur.
Something like
sys.isConsolePresent()
Have you tried:

sys.stdin.isatty()
sys.stdout.isatty()

Graham

Oct 18 '07 #2
On Oct 18, 2:56 pm, Metalone <j...@iteris.comwrote:
In particular I want to know how to tell if reading and writing to the
console can occur.
Something like
sys.isConsolePresent()
Look at sys.executable to find the name of the binary for the Python
interpreter.

Oct 19 '07 #3
On Oct 18, 11:56 pm, Metalone <j...@iteris.comwrote:
In particular I want to know how to tell if reading and writing to the
console can occur.
Something like
sys.isConsolePresent()
For a different problem, I have the following code. It might help:

def isrealfile(file):
"""
Test if file is on the os filesystem. This is necessary on windows,
when
starting python with pythonw.exe because in that case, the
stdout and stderr
are not real file and will create IOError when being flushed or when
more
than 4096 bytes are written.
"""
if not hasattr(file, 'fileno'): return False
try: tmp = os.dup(file.fileno())
except: return False
else: os.close(tmp); return True

class NullStream:
"""
A file like class that writes nothing
"""
def close(self): pass
def flush(self): pass
def write(self, str): pass
def writelines(self, sequence): pass

if not isrealfile(sys.stdout):
sys.stdout = NullStream()

if not isrealfile(sys.stderr):
sys.stderr = NullStream()
Oct 19 '07 #4
Thanks to all, I learned something in each post.
When using py2exe to build an executable sys.executable does not
provide the name of the python interpreter but the name of the
executable generated by py2exe.

Oct 19 '07 #5
Metalone schrieb:
Thanks to all, I learned something in each post.
When using py2exe to build an executable sys.executable does not
provide the name of the python interpreter but the name of the
executable generated by py2exe.
When running the executable built with py2exe you might be interested
in the variable sys.frozen; they are set to the string 'console' or 'windows', IIRC.

Thomas

Oct 19 '07 #6

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

Similar topics

3
by: Guyon Morée | last post by:
recently i've visited SARAH, the academic supercomputer in Amsterdam, Holland. this is next to the CWI, where Guido founded Python.... ....Yeah!...
8
by: Thomas Aanensen | last post by:
Python could be located at different paths on computers (e.g. c:\python). How can I find this path? Thomas
2
by: Eric Ching | last post by:
Can I run pythonw with a script that takes command line arguments then launches a GUI? I try pythonw myscript.pyw -option arg (etc.) and nothing happens. Nothing, as in I am immediately returned...
5
by: Shalen chhabra | last post by:
Hey, Can anyone give me a snippet for running a python program over all the files in the directory. For ex: I have ten files in a directory and I want to run a python program against all of...
0
by: Nicola Larosa | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 I find the following excerpt fairly sad... (right before the screenshot): "The first version of Scribus used Python, with the Python bindings...
1
by: Charles Stricklin | last post by:
I'd like to use Planet (http://planetplanet.org/) to aggregate my members blogs into one big blog, and my host (http://www.bodhost.com) says they support Python, but I see nothing anywhere on their...
5
by: johnny | last post by:
Anyone know how I can make Machine A python script execute a python script on Machine B ?
3
by: Brainsludge | last post by:
Hello, I am running WinXP SP2 with Python 2.5.1 and encountered the following issue: I wrote a script that logs into my mail server, and checks for new messages every 20 seconds. When a new...
1
by: Goldfish | last post by:
Spring Python, the python version of the Spring Framework, has just released version 0.8.0. This release contains a refactored IoC container supporting four formats (XMLConfig,...
2
by: giggsteve8 | last post by:
I'm very, very new, and am working with Python 3.1.2. New as in installed last night, and working through a tutorial. I wrote a simple script to aid in learning to break a 'while: True' loop. ...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
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...
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"....

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.