[kepler-dev] Running Shell Scripts inside Kepler
Dan Higgins
higgins at nceas.ucsb.edu
Wed Apr 6 09:06:11 PDT 2005
Hi Ilkay (and others)
A few weeks ago, you were asking if I had experience/problems with
running shell scripts using the CommandLine actor. At the time, I did
not, but that situation changed with some recent work on the RExpression
actor. And I discovered some problems (and solutions) which may be of
interest.
In the commandLine actor (and Java in general), the runtime.exec()
method is used to create subprocesses; e.g.
_process = runtime.exec(commandArray);
where, for the Windows OS, the commandArray might be something like
commandArray[0] = "cmd.exe";
commandArray[1] = "/C";
commandArray[2] = "R";
commandArray[3] = "--silent";
commandArray[4] = "--no-restore";
commandArray[5] = "--no-save";
In this case, the Windows command line processor 'cmd.exe' is used to
execute the 'R' program. This works fine on a Windows machine and use of
'cmd' to launch the R program means that the PATH system variable is
used to find R. Thus no need for specifying the absolute path.
Now, on Linux or MacOSX, the commandArray (for the CommandLine actor)
uses /bin/sh to execute the command line; e.g.
commandArray[0] = "/bin/sh";
commandArray[1] = "-c";
commandArray[2] = "R";
commandArray[3] = "--silent";
commandArray[4] = "--no-restore";
commandArray[5] = "--no-save";
Now here is where I ran into trouble!!! On Linux and the Mac, 'R' is a
shell script, not a simple executable! And apparently, the Java
runtime.exec() method WILL NOT START A SUBPROCESS SET UP THIS WAY WITH A
SHELL SCRIPT!!!
So what I discovered was that on Unix machines, I can change the
commandArray to directly call the shell script (i.e. not call the shell
to launch it). In this case, the commandArray is just
commandArray[0] = "R";
commandArray[1] = "--silent";
commandArray[2] = "--no-restore";
commandArray[3] = "--no-save";
This worked on both Linux and the MacOSX and the OS still can find a
shell script using PATH (which is cannot do under Windows).
So this solved my problem, but I am not sure exactly how it might work
for the CommandLine actor where it is not obvious whether or not one is
trying to run a shell script. Maybe, we can just drop the '/bin/sh' part
of the commandArray for executables AND shell scripts?
Dan
--
*******************************************************************
Dan Higgins higgins at nceas.ucsb.edu
http://www.nceas.ucsb.edu/ Ph: 805-893-5127
National Center for Ecological Analysis and Synthesis (NCEAS)
Marine Science Building - Room 3405
Santa Barbara, CA 93195
*******************************************************************
More information about the Kepler-dev
mailing list