os.popen() and (IDLE, PythonWin) ? 
Author Message
 os.popen() and (IDLE, PythonWin) ?

[os.popen('ver') fails under IDLE and PythonWin, yet works under "normal"
 Python]

Quote:

> Good call it is breaking under IDLE and Pythonwin.  It works under vanilla
> python though.

> ****************************Pythonwin************************************
> PythonWin 1.5.2 (#0, Apr 13 1999, 10:51:12) [MSC 32 bit (Intel)] on win32
> Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam

> >>> import platform
> >>> platform.platform()
> 'win32-4.0-1381-SP4'

> ****************************Vanila Python********************************
> Microsoft(R) Windows NT(TM)
> (C) Copyright 1985-1996 Microsoft Corp.

> C:\>python
> Python 1.5.2 (#0, Apr 13 1999, 10:51:12) [MSC 32 bit (Intel)] on win32
> Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
> >>> import os
> >>> os.popen('ver')
> <open file 'ver', mode 'r' at 7f6f90>
> >>> os.popen('ver').read()
> '\012Windows NT Version 4.0  \012'
> >>> import platform
> >>> platform.platform()
> 'Windows-NT-4.0-1381-SP4'

Any idea how to get this working with PythonWin and IDLE ? I know
there are some issues with pipes on Windows, but why should PythonWin
and IDLE fail when vanilla Python works ?

--
Marc-Andre Lemburg
______________________________________________________________________
Y2000:                                                    63 days left
Business:                                       http://www.*-*-*.com/
Python Pages:                           http://www.*-*-*.com/



Tue, 16 Apr 2002 03:00:00 GMT  
 os.popen() and (IDLE, PythonWin) ?

Quote:

> [os.popen('ver') fails under IDLE and PythonWin, yet works under "normal"
>  Python]

Ok, I found the FAQ entry on this:

7.13. Why doesn't os.popen() work in PythonWin on NT?

The reason that os.popen() doesn't work from within PythonWin is due to a bug in Microsoft's C Runtime
Library (CRT). The CRT assumes you have a Win32 console attached to the process.

You should use the win32pipe module's popen() instead which doesn't depend on having an attached Win32
console.

Example:

 import win32pipe
 f = win32pipe.popen('dir /c c:\\')
 print f.readlines()
 f.close()

Under PythonWin this is no problem (although I wish os.popen would
automatically choose the different approach for me in the above
setup). Yet under IDLE I have a problem: win32 doesn't have to be
installed... is there some other workaround ?

--
Marc-Andre Lemburg
______________________________________________________________________
Y2000:                                                    60 days left
Business:                                      http://www.lemburg.com/
Python Pages:                           http://www.lemburg.com/python/



Fri, 19 Apr 2002 03:00:00 GMT  
 os.popen() and (IDLE, PythonWin) ?

Quote:


> > [os.popen('ver') fails under IDLE and PythonWin, yet works
> > under "normal"
> >  Python]

> Ok, I found the FAQ entry on this:

> 7.13. Why doesn't os.popen() work in PythonWin on NT?
[snip]
> Under PythonWin this is no problem (although I wish os.popen
> would automatically choose the different approach for me in the
> above setup). Yet under IDLE I have a problem: win32 doesn't have
> to be installed... is there some other workaround ?

tempfile and redirection :-(.

- Gordon



Fri, 19 Apr 2002 03:00:00 GMT  
 os.popen() and (IDLE, PythonWin) ?

Quote:



> > > [os.popen('ver') fails under IDLE and PythonWin, yet works
> > > under "normal"
> > >  Python]

> > Ok, I found the FAQ entry on this:

> > 7.13. Why doesn't os.popen() work in PythonWin on NT?
> [snip]
> > Under PythonWin this is no problem (although I wish os.popen
> > would automatically choose the different approach for me in the
> > above setup). Yet under IDLE I have a problem: win32 doesn't have
> > to be installed... is there some other workaround ?

> tempfile and redirection :-(.

Ok, but how can I prevent the shell windows
from popping up ? I read something about os.spawnv() in the docs,
but the mode argument remains a complete mystery and I always
get IOErrors about files not being found...

Any help appreciated :-),
--
Marc-Andre Lemburg
______________________________________________________________________
Y2000:                                                    60 days left
Business:                                      http://www.lemburg.com/
Python Pages:                           http://www.lemburg.com/python/



Fri, 19 Apr 2002 03:00:00 GMT  
 os.popen() and (IDLE, PythonWin) ?

Quote:

> Ok, but how can I prevent the shell windows
> from popping up ? I read something about os.spawnv() in the docs,
> but the mode argument remains a complete mystery and I always
> get IOErrors about files not being found...

recently seen on c.l.py:

Subject: Re: How to eliminate consol window in MS Windows
Date: Thu, 28 Oct 1999 08:59:53 +0200

Quote:

> and what is worse, the program does not run in the background
> I'd really like to use
> os.spawnv(os.P_NOWAIT, "program.pyw", ("program.pyw", args))
> but it does not work at all... am I missing something?
> (I tried with the whole path, still nothing....)
> (note: I know next to nothing about programming under MS windows.. I am
> trying to do a quick port of my unix script)

you could try something like:

file = r"\full\path\pythonw.exe"
os.spawnv(os.P_NOWAIT, file, (file, "program.pyw") + tuple(args))

note that spawnv doesn't scan the path, and that
you need to pass the name of the excutable as the
first item in the argument tuple.

the following sample script from the eff-bot guide
shows one way to locate the executable:

# File: os-spawn-example-2.py

import os
import string

def run(program, *args, **kw):
    # find executable
    mode = kw.get("mode", os.P_WAIT)
    for path in string.split(os.environ["PATH"], os.pathsep):
        file = os.path.join(path, program) + ".exe"
        try:
            return os.spawnv(mode, file, (file,) + args)
        except os.error:
            pass
    raise os.error, "cannot find executable"

run("python", "hello.py", mode=os.P_NOWAIT)
print "goodbye"

</F>

<!-- (the eff-bot guide to) the standard python library:
http://www.pythonware.com/people/fredrik/librarybook.htm
-->



Sat, 20 Apr 2002 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Using os.system and os.popen from pythonwin under Windows NT

2. os.popen() vs os.system()

3. os.system/os.popen ultrasparc

4. Blocking ctrl-c to os.popen() or os.system()

5. Pythonwin popen() problem

6. Nested Scopes in Idle/PythonWin

7. Importing wxPython under IDLE 0.5 fails though ok under raw python or pythonwin

8. Comparing PythonWin and IDLE?

9. Anyone working on IDLE or PythonWin for CE?

10. Using IDLE or PythonWin and TkInter

11. Using IDLE or PythonWin and TkInter

12. IDLE and pythonwin won't run

 

 
Powered by phpBB® Forum Software