Redirect output
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.python archive

Redirect output

From: abcd <codecraig@gmail.com>
Date: Tue Mar 28 2006 - 20:45:06 CEST

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.
Received on Sun Apr 30 21:27:03 2006