troubleshooting Question

Capturing standard output from JavaTcl Interp

Avatar of jksung
jksung asked on
JavaScripting Languages
5 Comments1 Solution310 ViewsLast Modified:
I am running third party TCL functions with Java using the JavaTCL library.  I want to capture what is being sent to standard out for commands such as:

import tcl.lang.Interp;
import tcl.lang.TclException;

public class Temp {

      public Interp tclInterp;
       
        public static void main() {
                tclInterp = new Interp;
                tclInterp.eval("LoadConfig xxx.cfg");
        }
}

I've tried redirecting the standard out to something like a ByteArrayOutputStream, however, that only captures what is specifically send to System.out from the program, it does not capture what is being sent to standard out from the command "tclInterp.eval("LoadConfig xxx.cfg");".

For example, if I do something like:

ByteArrayOutputStream out = new ByteArrayOutputStream();
System.setOut(new PrintStream(out));
tclInterp.eval("LoadConfig xxx.cfg");
System.out.println("temp");
String collected = new String(out.toByteArray());

the string "collected" will only contain "temp".

Anyone have any ideas?
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 5 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros