Hi,
Under cint, we can suffix “>” to redirect the output. But do we have to run something like under PyROOT:
Is it possible to redirect the output of “chain.Print()” within python? And where is the function “Printf” defined in ROOT?
Thanks
–Shuwei
Shuwei,
not as easily … in python you can simply redirect stdout from python objects by setting sys.stdout to another stream, but for general writes that are coming from C/C++ you’d have to dup stdout and set it to something different for redirection.
For example:
import os, sys save = os.dup( sys.stdout.fileno() ) newout = file( 'filename.out', 'w' ) os.dup2( newout.fileno(), sys.stdout.fileno() ) c.Print() os.dup2( save, sys.stdout.fileno() ) newout.close() Cheers, Wim
import os, sys save = os.dup( sys.stdout.fileno() ) newout = file( 'filename.out', 'w' ) os.dup2( newout.fileno(), sys.stdout.fileno() ) c.Print() os.dup2( save, sys.stdout.fileno() ) newout.close()