Interview Questions

How do I run a subprocess with pipes connected to both input and output?

Python Questions and Answers


(Continued from previous question...)

How do I run a subprocess with pipes connected to both input and output?

Use the popen2 module. For example:

import popen2
fromchild, tochild = popen2.popen2("command")
tochild.write("input\n")
tochild.flush()
output = fromchild.readline()

(Continued on next question...)

Other Interview Questions