Login  Register

Re: Run native executable in a plugin, Apache commons exec or processbuilder???

Posted by dscho on Oct 15, 2014; 8:54pm
URL: http://imagej.273.s1.nabble.com/Run-native-executable-in-a-plugin-Apache-commons-exec-or-processbuilder-tp5010068p5010072.html

Hi Dan,

On Wed, 15 Oct 2014, Daniel White wrote:

> Hi Dschowe,

Almost.

> On Wednesday, October 15, 2014, Johannes Schindelin <
> [hidden email]> wrote:
>
> > On Wed, 15 Oct 2014, Daniel White wrote:
> >
> > > Did anyone ever make a plugin or script or macro that runs a native
> > > executable as a sub process  , perhaps using Apache commons exec or the
> > > native Java processbuilder?
> >
> > Yep, sure I do. The org.scijava.util.ProcessUtils is designed to help you
> > with that:
> >
> >
> > http://jenkins.imagej.net/job/SciJava-common-javadoc/javadoc/org/scijava/util/ProcessUtils.html
> >
> > [...]
>
>
> So if the eg. Linux executable might take a long time to run, Should I
> also make sure it can be killed if it hangs or times out , and somehow
> catch its successful completion signal... To know when I can then get
> imageJ to load the result image file, if I want the plugin to also do
> that.

The utilities I presented do not have (yet) options for a timeout. For the
moment, you need to use Java6' ProcessBuilder (or System.exec()) for that,
and kill the Process if it runs too long a time.

Or you contribute the feature by modifying SciJava commons' ProcessUtils.

> Should I also make sure the executable runs in a different thread to the
> GUI? So it doesn't block important stuff?

Yes, you need to run this on a different thread. Killing the thread will
not kill the process, BTW.

> what to watch out for to make sure the plugin could also be run in a
> headless situation ? Separate the GUI from the part that does the
> execution I guess...

That is one thing to watch out for, yes.

> And to make sure the plugin can be run in batch mode via the multi image
> processor, or what ever it's called these days....
>
> Dos and don'ts to make sure it's as general as possible?

Ideally, if you require a bit more than the current library versions
provide (such as the timeout feature), it is preferable to enhance the
library. That way, many plugins can benefit from a generic, reusable
solution.

If you have some public source code repository with the work in progress,
feel free to point me to it so I can have a look.

Ciao,
Dscho

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html