I remember seeing a hack that would do what you want at some point
on the list (It might have been before the list was archived). If
I remember correctly you would need to create a
java.io.ByteArrayOutputStream to hold the data to be written.
Then you would wrap a PrintStream around that and call the
System.setOur(PrintStream) method. After doing that calls to
System.out.println() would write to the in-memory buffer. You
could also hook calls to stderr using setErr(java.io.PrintStream).
You could then get the contents of the output buffer with the toString()
method. I guess you would need to poll for writes on the byte array.

I hope that helps
Mo DeJong


On Thu, 18 Nov 1999, Thomas McKay wrote:

> 
> In most cases I do try to use setResult().  However, there are places where,
> for example, progress information is displayed.  This info is for the user's
> benefit while the command is being executed.  To wait until the command has
> finished would defeat this purpose.
> 
> Good idea, though.
> 
> > -----Original Message-----
> > From: Shawn Boyce [mailto:[EMAIL PROTECTED]]
> > Sent: Thursday, November 18, 1999 8:06 AM
> > To: [EMAIL PROTECTED]
> > Cc: Jacl
> > Subject: [Tcl Java] Re: [Tcl Java] more on redirecting stdin/stdout
> >
> >
> > Instead of doing puts, you should use the setResult() method.
> >
> > e.g.
> >
> > interp.setResult( "Result of the command" );
> >
> > The Jacl interpreter will then write the string to the console.
> > You can also save the output of the command like this:
> >
> > set ret [my_custom_cmd arg1 arg2]
> > if { $ret == "expected result" } {
> >     puts "test passed"
> > } else {
> >     puts "test failed"
> > }
> >
> > -Shawn
> >
> > Thomas McKay wrote:
> >
> > > Okay, I found the archive at
> > > http://www.mail-archive.com/tcljava@scriptics.com/ .
> > >
> > > Here's what I'm trying to do...  Some of my custom command extensions to
> > > Jacl generate textual output.  Now right now they simply print it in a
> > > console area of my application.  My goal is to use the Jacl
> > test framework
> > > to "catch" this output and compare it to what is expected.  Now
> > since the
> > > commands are effectively calling puts rather than returning a result, is
> > > there any standard way in Jacl (Tcl) to trap this?
> > >
> > > The one thought I had is to write a special command that forces
> > stdin/stderr
> > > to a string which is then returned.  Maybe eval can already do this?
> > >
> > > ---
> > > Thomas McKay
> > >
> > > Project Leader
> > > Microcosm Technologies, Inc.
> > > mailto:[EMAIL PROTECTED]
> > >
> > > ----------------------------------------------------------------
> > > The TclJava mailing list is sponsored by Scriptics Corporation.
> > > To subscribe:    send mail to [EMAIL PROTECTED]
> > >                  with the word SUBSCRIBE as the subject.
> > > To unsubscribe:  send mail to [EMAIL PROTECTED]
> > >                  with the word UNSUBSCRIBE as the subject.
> > > To send to the list, send email to '[EMAIL PROTECTED]'.
> >
> > --
> > Shawn Boyce
> > QCOM Inc.
> > Email: [EMAIL PROTECTED]
> > Phone: (732) 617-1970 x11
> > Fax:   (732) 617-1975
> > Web:   http://www.qcominc.com/people/shawn
> >
> >
> > ----------------------------------------------------------------
> > The TclJava mailing list is sponsored by Scriptics Corporation.
> > To subscribe:    send mail to [EMAIL PROTECTED]
> >                  with the word SUBSCRIBE as the subject.
> > To unsubscribe:  send mail to [EMAIL PROTECTED]
> >                  with the word UNSUBSCRIBE as the subject.
> > To send to the list, send email to '[EMAIL PROTECTED]'.
> >
> 
> ----------------------------------------------------------------
> The TclJava mailing list is sponsored by Scriptics Corporation.
> To subscribe:    send mail to [EMAIL PROTECTED]  
>                  with the word SUBSCRIBE as the subject.
> To unsubscribe:  send mail to [EMAIL PROTECTED] 
>                  with the word UNSUBSCRIBE as the subject.
> To send to the list, send email to '[EMAIL PROTECTED]'. 
> 

----------------------------------------------------------------
The TclJava mailing list is sponsored by Scriptics Corporation.
To subscribe:    send mail to [EMAIL PROTECTED]  
                 with the word SUBSCRIBE as the subject.
To unsubscribe:  send mail to [EMAIL PROTECTED] 
                 with the word UNSUBSCRIBE as the subject.
To send to the list, send email to '[EMAIL PROTECTED]'. 

Reply via email to