caputering IO in python

Greg Ewing see at my.signature
Thu Aug 17 23:52:56 EDT 2000


Curtis Jensen wrote:
> 
> However, my C module calls Fortran
> that does the writes to standard output.  The Fortran output is the
> output I wish to capture.  Is this possible?

No, changing sys.stdout won't affect that sort of output.
On Unix, the easiest way would be to do the redirection
outside of the program, e.g. using the shell.

If you have to be able to redirect from within the
program, you could try, in C:

   freopen(filename, "w", stdout);

or in Python:

   import posix, sys
   f = open(filename, "w")
   sys.stdout.flush()
   posix.dup2(f.fileno(), 1)

-- 
Greg Ewing, Computer Science Dept, University of Canterbury,	  
Christchurch, New Zealand
To get my email address, please visit my web page:	  
http://www.cosc.canterbury.ac.nz/~greg



More information about the Python-list mailing list