Posted by
dscho on
Feb 27, 2013; 9:24pm
URL: http://imagej.273.s1.nabble.com/Using-System-out-and-System-err-from-ImageJ-plugins-Java-tp5001799p5001905.html
Dear Wayne,
On Wed, 27 Feb 2013, Johannes Schindelin wrote:
> On Wed, 27 Feb 2013, Johannes Schindelin wrote:
>
> > On Wed, 27 Feb 2013, Rasband, Wayne (NIH/NIMH) [E] wrote:
> >
> > > You can redirect System.out and System.err messages to the Log
> > > window by enabling debug mode in Edit>Options>Misc.
> >
> > [...] this interferes with Fiji's stdout/stderr handling. I am fixing
> > it as we speak.
>
> I just tested this Javascript after downloading and starting
>
http://imagej.net/ij.jar:>
> importClass(Packages.java.lang.System);
> System.err.println("Hello");
>
> It did not interfere with Fiji's redirection -- unexpectedly.
I found out why it did not work in my test: I activated the debug mode
using the -debug command-line option. And while it seems that the very
same code was added in three places (ij.macro.Functions#setOption(),
ij.plugin.Options#miscOptions() and ij.text.TextWindow#close(boolean)), it
was not added at the two other places in ij.jar where debugMode can be
activated: ij.macro.Functions#restoreSettings() and
ij.ImageJ#main(String[]).
And of course, all 3rd-party plugins setting IJ.debugMode directly cannot
trigger the redirection automatically. That is why I took pains of
switching on the redirection at all times, mirroring the text to the Log
window only when IJ.debugMode == true.
This is unfortunately not the only issue I fixed in Fiji's redirection and
that frustratingly now crops up again in ImageJ 1.x' reimplementation:
In batch mode, one needs to take great pains to avoid the redirection.
Otherwise, IJ#log(String) will detect that ImageJ is running in batch mode
and print to stdout instead. Which will ask IJ#log(String) to output
again, causing an infinite loop. You can easily reproduce that issue with
this command-line:
java -jar ij.jar -eval \
'setOption("debugmode", 1); eval("script", "importClass(Packages.java.lang.System); System.err.println(\"Hello\");");' \
-batch
Ciao,
Johannes
--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html