Thanks for the quick replies Claude, Andy, and Frank. Initially, I wanted a solution that captured both Jython's stdout as well as Java's. But as it turns out, Java's output is all I really care about. So, this solution will suite me just fine.

Thanks again!

On 4/5/07, claudef@br.ibm.com <claudef@br.ibm.com > wrote:

A quick translation of Java output redirection under Jython

from java.io import *
from java.lang import *
# ---method -------------------------------------------------------------------------------              
def redirect():
    directory = File("c:/jython/myprojects/redirect/")
    errFile = File.createTempFile("stderr", ".txt", directory)
    System.setErr(PrintStream(FileOutputStream(errFile)))
    outFile = File.createTempFile("stdout", ".txt", directory)
    System.setOut(PrintStream(FileOutputStream(outFile)))

# --main code -----------------------------------------------------------------------------  
System.out.println("test before redirect");
redirect()
System.out.println("test after redirect");

Have fun.

Regards,
Claude Falbriard

Developer
AMS Hortolāndia / SP - Brazil
phone: +55 13 8117 3316
e-mail:  claudef@br.ibm.com



"Jesse Millan" <j.L.A.millan@gmail.com>
Sent by: jython-users-bounces@lists.sourceforge.net

04/05/2007 05:07 PM

To
jython-users@lists.sourceforge.net
cc

Subject
[Jython-users] Problems redirecting stdout & stderr (globally)







Hello,

I need to redirect all stdout and stderr to files. This redirection
needs to also include the output of imported Java modules that I use.
The following example readily given on the Web only catches the
script's output, Jythons output - not external Java modules output:

sys.stdout = open("/tmp/jythonstdout", "w")
sys.stderr = open("/tmp/jythonstderr", "w")

print >> sys.stdout, "out"
# Java modules output is not captured

I then thought that I should instead use dup2, also a common example on the Web:

stdoutlog = open("/tmp/jythonstdout", "w")
stderrlog = open("/tmp/jythonstderr", "w")

os.dup2(stdoutlog.fileno(), sys.stdout.fileno())
os.dup2(stderrlog.fileno(), sys.stderr.fileno())

Unfortunately, the above code produces the following error: NameError:
name "file" is not defined. I took this as a sign that I'm supposed to
be using open() instead of file, which is said to be an alias for
file(). Except, that also generates an error:

IOError: fileno() is not supported in jpython

Can someone please steer me in the right direction?

Thanks a million!

-Jesse

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Jython-users mailing list
Jython-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jython-users


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Jython-users mailing list
Jython-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jython-users