win32pipe.popen3

Adriaan Renting renting at astron.nl
Thu Aug 18 09:04:23 CEST 2005


Well, on Linux I use select first to see if there's something to read. Maybe this works on Windows too?

This is my code: 
                    fd = os.open(filename, os.O_NONBLOCK)
                    ready = select.select([fd], [], [], 0.25) ## timeout after 0.25 seconds.
                    if fd in ready[0]:
                        text  = os.read(fd, 1024)
                        lines = text.split('\n')
                        for line in lines:
                            print line
                    else:
                        print '-'
                    os.close(fd)

You can maybe use select.poll too.
 
>>>"Jakob Simon-Gaarde" <jsgaarde at gmail.com> 08/17/05 7:51 pm >>> 
Follow-up on a thread from 1999 (see below) 
 
Well now it is 2005 and the operating system I'm using is Windows 
Server 2003, and I can still see that the same problem persists with: 
 
win32pipe.popen2() 
win32pipe.popen3() 
win32pipe.popen4() 
 
while win32pipe.popen() does almost what you want. 
 
>>>import win32pipe 
>>>win32pipe.popen('cmd') 
<open file 'cmd', mode 'r' at 0x009DD698> 
>>>r=win32pipe.popen('cmd') 
>>>r.readline() 
'Microsoft Windows XP [Version 5.1.2600]\n' 
>>>r.readline() 
'(C) Copyright 1985-2001 Microsoft Corp.\n' 
>>>r.readline() 
'\n' 
>>>r.readline() 
'C:\\backup\\TRPython241\\trpython>' 
 
Although I think the last readline ought to return None since no 
carriage return has been issued yet, it is better than popen2,popen3 
and popen4, which all just block the parent process. 
 
The current behaviour of win32pipe.popen2(), win32pipe.popen3() and 
win32pipe.popen4() would be acceptable for me if I knew a way to test 
if there was something ready for reading, but I can't see how to do 
that test, therfore I don't know when to stop reading from output :( Is 
there a solution for this, can I poll/test for ready-read on popen3 I/O 
objects. 
 
Best regards 
Jakob Simon-Gaarde 
 
 
--------------------------- 
>From a thread in 1999 
High Arpard, 
 
thanx for help but I got probs with that popen3 under Win95: 
'o.readlines()' doesn't return anymore. To find out I checked 
it line per line: 
 
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 win32pipe 
>>>i,o,e=win32pipe.popen3('ver', 'b') 
>>>o.readline() 
'\015\012' 
>>>o.readline() 
 
'Windows 95. [Version 4.00.1111]\015\012' 
 
>>>o.readline() 
'\015\012' 
>>>o.readline() 
 
Don't know why, but it never;-) returns. 
Perhaps it may be a bug in win32pipe, that it doesn't return 
becourse readline couldn't find CarriageReturn/EOF? 
 
I took win32pipe.popen('ver','r') for a better solution. 
That works fine. 
 
greetings, 
Holger 
 
-- 
http://mail.python.org/mailman/listinfo/python-list 




More information about the Python-list mailing list