Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Is there a way to tell if a script has been run by Pythonw.exe instead of Python.exe?

Reply
Thread Tools

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

 
 
Metalone
Guest
Posts: n/a
 
      10-18-2007
In particular I want to know how to tell if reading and writing to the
console can occur.
Something like
sys.isConsolePresent()

 
Reply With Quote
 
 
 
 
Graham Dumpleton
Guest
Posts: n/a
 
      10-18-2007
On Oct 19, 7:56 am, Metalone <(E-Mail Removed)> wrote:
> 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

 
Reply With Quote
 
 
 
 
michaelvmata@gmail.com
Guest
Posts: n/a
 
      10-19-2007
On Oct 18, 2:56 pm, Metalone <(E-Mail Removed)> wrote:
> 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.

 
Reply With Quote
 
BlueBird
Guest
Posts: n/a
 
      10-19-2007
On Oct 18, 11:56 pm, Metalone <(E-Mail Removed)> wrote:
> 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()


 
Reply With Quote
 
Metalone
Guest
Posts: n/a
 
      10-19-2007
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.

 
Reply With Quote
 
Thomas Heller
Guest
Posts: n/a
 
      10-19-2007
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
anyway to tell if office 2003 CD has been used? Dr Nick Computer Information 2 02-09-2006 11:20 PM
The printing has been stopped and this job has been add to the queu? dejola Computer Support 6 12-30-2005 03:26 AM
How to tell if an exception has been caught ( from inside theexception )? Paul Dale Python 1 09-22-2005 01:56 PM
How to tell which row in datagrid has been clicked. Terry Olsen ASP .Net 3 07-12-2005 09:51 AM
Please take a look at my site and tell me what you think. Everything here has been shot digital high res. Dan Digital Photography 6 11-05-2003 07:49 AM



Advertisments