Login  Register

Re: making system call from a plugin

Posted by Michael Schmid on Dec 04, 2014; 5:54pm
URL: http://imagej.273.s1.nabble.com/making-system-call-from-a-plugin-tp5010767p5010768.html

Hi Joe,

search the Web for "Runtime.getRuntime().exec" (on Google with the quotes), and you will find many examples.
On OS X and Linux, you can directly use the String as you type it in the terminal, on Windows you will have to prepend "cmd /c " to the command String.

If you want to specify a default directory (path) to be used by the program, the three-argument form is best:

try {
  Process p = Runtime.getRuntime().exec("/home/me/bin/myexecutable", //command
                null, //may be a String[] with environmental parameters,
                myPathDirectory);
  /here you may read your program's stdout from p.getInputStream()
} catch (Exception e) {
  //handle errors
}

By the way, also the ImageJ macro language can do this, see the exec macro command.

Michael
________________________________________________________________
On Dec 4, 2014, at 17:24, Joe Vandergracht wrote:

> Short version of question:   Can I call a system level command from a plug in.
>
> Long version:  I have compiled executables from my own C code that run from the command line in a Mac OS X terminal or Xterminal window.  For example an executable might be called myexecutable.  I can run that program by opening a terminal window and typing
>
> ./myexecutable
>
> at the prompt, provided I have first navigated to the correct directory.  Not sure why the period and forward slash are needed in front of the executable name, but that's what works in OS X.
>
> I would like to have an ImageJ plugin open up a terminal window, go to the correct directory and execute  the program.
>
> Is this feasible?  If so, any tips or resources would be appreciated.  I am not expert in Java by any means so pointing to examples would be greatly appreciated.
>
> thanks
>
> Joe vanderGracht
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html

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