imagej-launcher icon indicating copy to clipboard operation
imagej-launcher copied to clipboard

Use java.exe when --headless and --run are set

Open stelfrich opened this issue 7 years ago • 5 comments

At least on Windows 10 (haven't tested other versions) the following call will not return even if the Jython script exits:

$ .\ImageJ-win64.exe --ij2 --headless --console --run someScript.py

The problem can be remedied by using java.exe instead of javaw.exe in the aforementioned configuration. That is, I would expect the ImageJ process to exit when a script that I execute with --headless --run exits.

See also:

  • http://forum.imagej.net/t/need-help-with-exiting-python-script/7832/8

stelfrich avatar Nov 27 '17 09:11 stelfrich

The launcher, unless it is "falling back to system java", does not use java.exe nor javaw.exe at all. Rather, it dynamically links to the JVM shared library. The --console flag, if I understand correctly, is supposed to attach to the win32 console; see the open_win_console method in platform.c. See also #29 for related discussion.

ctrueden avatar Nov 28 '17 00:11 ctrueden

Hi guys,

this is really beyond my expertise, but on my windows system the usage of

ImageJ-win64.exe --dry-run --ij2 --headless --console

generates the following output:

javaw -Dpython.cachedir.skip=true -Dplugins.dir=FJD -Xmx8000m -Djava.awt.headless=true ...

This cause the described issues in:

http://forum.imagej.net/t/need-help-with-exiting-python-script/7832/8

And when I change javaw against java the issue is gone. So what exactly is changed when using one vs. the other. My Fiji comes with its own java located in c:\Users\Public\Documents\Fiji\java\win64\jdk1.8.0_66\jre.

Let me know, if I can be of any further help.

sebi06 avatar Nov 28 '17 09:11 sebi06

@sebi06 Thanks for your comment. Indeed, javaw.exe and java.exe are different. However, the --dry-run flag produces only a best-effort approximation of what the launcher does normally. As I said above, the launcher normally does not invoke either of those two executables, but rather links against a shared library.

I am sorry, but I am far from a Windows expert, and do not have time to troubleshoot this issue this year. If someone who knows the Windows native environment would care to file a PR against the ImageJ launcher, though, that would certainly be appreciated.

In the meantime, invoking java.exe directly with the requisite command line flags is probably your best bet.

ctrueden avatar Nov 28 '17 19:11 ctrueden

If you remove the --console argument, the command line returns to a new feed. But right after pressing enter, not once the script execution is over. Yet when calling fiji this way from an external program, the external program indeed detected the end of the execution. I don't know though if you can recover what was printed to the console in the external program (maybe using an output file would be a safer option).

LauLauThom avatar Sep 14 '18 13:09 LauLauThom

Another report of a similar issue (that I'll leave here for reference): https://forum.image.sc/t/console-application-doesnt-exit/19791/

stelfrich avatar Sep 24 '18 05:09 stelfrich