[kepler-dev] Running Shell Scripts inside Kepler
Dan Higgins
higgins at nceas.ucsb.edu
Wed Apr 6 09:25:57 PDT 2005
Christopher,
I was also surprised also that the "bin/sh" technique did not work.
In any case, changing it fixed things on both the Mac and on Linux !
Maybe there is something specific in the R script?
Dan
Christopher Brooks wrote:
>BTW - My hack for the exec command in ptjacl (a 100% Java
>implementation of a subset of Tcl)
>was to add a -sh command line argument. If -sh is present, then
>we use /bin/sh, if not, then we use cmd under Windows etc.
>
>The ptjacl exec command is written in Java and uses the
>Runtime.exec(), so it is very similar to CommandLine.
>
>I'm not sure if this would help with CommandLine. It seems dumb
>to have to tell the tool whether to use /bin/sh or not, but at
>the time it seemed like the quickest solution. It looks
>like the problem for here is that sometimes you want /bin/sh,
>sometimes you don't. I'm surprised that under Linux and
>the Mac, the following did not work for you.
>
> commandArray[0] = "/bin/sh";
> commandArray[1] = "-c";
> commandArray[2] = "R";
> commandArray[3] = "--silent";
> commandArray[4] = "--no-restore";
> commandArray[5] = "--no-save";
>
>BTW - Under Windows the ptjacl exec command writes out two files
>c:/temp/jacl1.bat and c:/temp/jacl2.bat
>
>jacl1.bat looks like:
>--start--
>@echo off
>cmd.exe /C C:\TEMP\jacl2.bat
>--end--
>
>--start--
>@echo off
>C:
>cd \cxh\ptII\ptolemy\copernicus\java\test
>make "-C" "../cg/ComplexDivide" "MODEL=ComplexDivide"
>"SOURCECLASS=../../../../ptolemy/actor/lib/test/auto/ComplexDivide.xml"
>"smokeTest"
>--end--
>
>This seems a litle byzantine, but it works.
>
>_Christopher
>
>
>
>--------
>
> 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";
>p
> 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
> *******************************************************************
>
> _______________________________________________
> Kepler-dev mailing list
> Kepler-dev at ecoinformatics.org
> http://mercury.nceas.ucsb.edu/ecoinformatics/mailman/listinfo/kepler-dev
>--------
>
>
--
*******************************************************************
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