Reading a subprocesses stdout on Windows

Do Re Mi chel La Si Do enleverlesO.OmcO at OmclaveauO.com
Mon Nov 21 15:50:44 EST 2005


Hi!

Let down subprocess, and remember  popen4.

Here, an example (with  CMD, under w-XP) :

import os

def lcmd(lst=None):
    a = os.popen4(lst[0])
    for i in lst[1:]:
        if i!='':
            a[0].write(i+'\r\n')
            a[0].flush()
    return a[1].readlines()

l=[
'CMD /K',
'DIR *.c /B',
'DATE /T',
'TIME /T',
'EXIT'
]
lret = lcmd(l)
for n in lret:
    print n[:-1]



Attention : don't read data inside the loop (for)...



@-salutations

Michel Claveau






More information about the Python-list mailing list