runtime fails when command has arguments
Posted by
jvander on
Dec 10, 2014; 11:08pm
URL: http://imagej.273.s1.nabble.com/runtime-fails-when-command-has-arguments-tp5010889.html
A few days I asked about running Mac OS X system commands from an ImageJ plugin. I got two suggestions and had some success with Michaels approach below (thanks Michael):
try {
Process p = Runtime.getRuntime().exec("/path/myexecutable");
/here you may read your program's stdout from p.getInputStream()
} catch (Exception e) {
//handle errors
}
This works when the command has no arguments. I can verify that the executable runs because that particular executable processes a file and saves it. The action does indeed occur.
I run into problems when my command has arguments. Specifically, now I am trying to run a scilab script. (Scilab is an opensource matlab-like program). When I type the following from a terminal window it works:
/Applications/scilab-5.4.1.app/Contents/MacOs/bin/scilab-cli -f sciscript
In this case the arguments call a script that runs in scilab and then exits. This works fine from the terminal. But when I try to call it using runtime from a plugin as follows,
Process p = Runtime.getRuntime().exec("/Applications/scilab-5.4.1.app/Contents/MacOs/bin/scilab-cli -f sciscript");
I can verify that scilab opens as a process but it does not appear to recognize the arguments because the scilab process opens but the script actions never happens and the process does not exit. I can see the process running when I check the active system processes. Keep in mind that this works from the terminal, it only fails in runtime.
So my first question is whether anyone can spot my mistake. Perhaps it has something to do with the blank spaces between arguments. (I tried zapping gremlins). If nobody has ideas, it would help if I could see what error message might be being sent out as stdout. Michael provides a tip above, but actually accessing that output is proving difficult. More direction would be appreciated if someone has some readymade code using p.getInputStream() already.
thanks,
Joe vanderGracht
--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html