imagej / imagej-launcher

The ImageJ native launcher
https://imagej.net/learn/launcher
BSD 2-Clause "Simplified" License
21 stars 23 forks source link

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

Open stelfrich opened 6 years ago

stelfrich commented 6 years ago

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:

ctrueden commented 6 years ago

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.

sebi06 commented 6 years ago

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.

ctrueden commented 6 years ago

@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.

LauLauThom commented 5 years ago

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).

stelfrich commented 5 years ago

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