redirecting output
Oliver Schaefer
SchaeferFFM at hotmail.com
Sun Mar 5 18:09:24 EST 2000
Hi,
Good news!
os.popen still doesn't work on Win 9x, but win32pipe.popen,
win32pipe.popen2 and win32pipe.popen3 do work if you have recent versions
of msvcrt installed.
I have installed the Y2K patch from MS ("W95Y2K.EXE" - 2228 KB)
and *since then*, the following test script worked flawlessly from
within PythonWin, IDLE and generally with pythonw.exe.
FYI, I have Win 95 B, win32all-128 and Python 1.5.42 (stackless) installed.
Regards,
Oliver Schaefer [ SchaeferFFM at gmx.de ]
[test_popen.py]------------------------------
import win32pipe, sys
write = sys.stdout.write
def test_popen(cmd='dir *.py'):
return win32pipe.popen(cmd).read()
# def test_popen(cmd='dir *.py')
def test_popen2(cmd='python -i', line='print "hi"'):
writer, reader = win32pipe.popen2(cmd)
writer.write('%s\n' % line)
return reader.readline()
# def test_popen2(cmd='python -i', line='print "hi"')
def test_popen3(cmd='python -h'):
writer, reader, err = win32pipe.popen3(cmd)
return err.read()
# def test_popen3(cmd='python -h')
def test():
print ">>> win32pipe.popen('dir *.py').read()"
write(test_popen())
print ">>> writer, reader = win32pipe.popen2('python -i')"
print r'''>>> writer.write('print "hi"\n')'''
print '>>> reader.readline()'
write(test_popen2())
print ">>> win32pipe.popen3('python -h')[2].read()"
write(test_popen3())
# def test()
if __name__ == '__main__':
test()
[EOF]-------------------------------
----- Original Message -----
From: Niels Diepeveen <niels at endea.demon.nl>
Newsgroups: comp.lang.python
Sent: Friday, March 03, 2000 5:39 PM
Subject: Re: redirecting output
>
>
> Emile van Sebille schreef:
>
> > >>> import os
> > >>> os.popen("dir").read()
> > Traceback (innermost last):
> > File "<pyshell#1>", line 1, in ?
> > os.popen("dir").read()
> > OSError: (0, 'Error')
>
> os.popen only works in a console session, not from pythonw. This is a
> problem in the C library.
>
> --
> Niels Diepeveen
> Endea automatisering
>
>
More information about the Python-list
mailing list