This is the mail archive of the
kawa@sources.redhat.com
mailing list for the Kawa project.
Re: OutPort.setOutDefault(...)
Pinte_Stanislas@emc.com wrote:
> hello,
>
> I think the Outport is bugged somehow, because when I do this:
>
> Scheme scheme = null;
> StringWriter outStringWriter = new StringWriter();
> StringWriter errStringWriter = new StringWriter();
> OutPort.setOutDefault(new OutPort(outStringWriter, true, "out"));
> OutPort.setErrDefault(new OutPort(errStringWriter, true, "err"));
> scheme = new Scheme();
> scheme.eval("(display 'hello)");
> System.out.println("out: " + outStringWriter.toString());
> System.out.println("err: " + errStringWriter.toString());
>
> nothing gets printed, whereas "hello" should be outputted to the standard
> out port, shouldn't it?
>
> is this not the desired behaviour?
No, this doesn't work, and is not claimed to work.
The default output port is initialized to System.out, but they are
not otherwise connected. If might be nice if they were, but there
are at least two problems:
(1) OutPort.setOutDefault takes an OutPort. System.setOut takes a
printStream. You would need a bi-directional bridge from an
OutPort to a PrintStream and vice versa.
(2) The default OutPort is thread-specific, though there is a global
default.
--
--Per Bothner
per@bothner.com http://www.bothner.com/per/