How to do os.popen with write and read at the same time?
Benyang Tang
btang at pacific.jpl.nasa.gov
Tue Mar 14 02:11:03 EST 2000
One of the readers kindly suggested using popen2. I got it working. Here is the code:
#!/usr/bin/env python
import os, popen2
execFile = 'a.out'
dataFile = 'dataIn\n'
iCol = 1
out1,in1 = popen2.popen2(execFile)
print out1, in1
in1.write(dataFile)
in1.write(str(iCol)+'\n')
in1.close() # in1 has to be closed before execFile runs?
a = out1.read()
out1.close()
print a
#===============================================
Benyang Tang wrote:
>
> I like to do thing like:
>
> stdin > grep 'something' >stdout
>
> How do I access stdin and stdout in python?
> os.popen accepts either 'w' or 'r' mode, but not both at the same time.
--
<> Benyang Tang office: 818/354-0327 <>
<> 300-323, JPL fax: 818/393-6720 <>
<> 4800 Oak Grove Drive mail: btang at pacific.jpl.nasa.gov <>
<> Pasadena, CA 91109, USA <>
More information about the Python-list
mailing list