Redirect output
abcd
codecraig at gmail.com
Tue Mar 28 13:45:06 EST 2006
I have a program which is written in C and interfaced with python via
Swig. However, the function I call prints stuff out to the console. I
would like to capture what it is printing out. I tried:
[code]
import MyCProg, sys
f = open("tmp.txt", "wb")
sys.stdout = f
MyCProg.getData()
f.close()
sys.stdout = sys.__stdout__
print open("tmp.txt", "rb").read()
[/code]
However, it just prints the data to the screen. I tried redirecting
stderr as well.
other than modifying the C code and re-generating the interface via
Swig, any ideas? just asking before i have to do that.
More information about the Python-list
mailing list