[GRASS-user] grass shell

Glynn Clements glynn at gclements.plus.com
Wed Mar 3 23:51:28 EST 2010


maven apache wrote:

> I want to know  the shell used by grass when run it in command line ?

It uses the shell specified by $SHELL.

> Because I met a problem when I tried to call grass in my java web
> application,the output of the same cmd are different.
> Details:
> I use the grass-batch-job manner to run the grass in terminal, the
> batjob file is attached as the grass.sh.

If you set GRASS_BATCH_JOB, it is executed instead of the shell.

> Then I tried to run it in the java, the java code is shown in the
> attach RuntimeT.java:

> 		String[] env={"GRASS_BATCH_JOB=/home/kk/MavenTest/MParent/mserver/src/main/resources/org/kingxip/grass.sh"};
> 		try {
> 			Process p1=Runtime.getRuntime().exec(cmd, env);

> However when I run this code, the process hang up ,and the output is
> not the same as the terminal, shown in the attach GrassInJava.png.
> 
> So, what is the problem?

With java.lang.Runtime.exec(String cmd, String[] envp), the envp
parameter specifies the entire environment for the process (i.e. it
doesn't add the strings to the current process' environment). The
result is that HOME isn't set, which means that $HOME/.grassrc6 cannot
be found, so it displays the "first use" screen and waits for the user
to press a key:

	# First time user - GISRC is defined in the GRASS script
	if [ ! -f "$GISRC" ] ; then
	
	    if [ ! -f "$GISBASE/locale/$LCL/etc/grass_intro" ] ; then
		cat "$ETC/grass_intro"
	    else
		cat "$GISBASE/locale/$LCL/etc/grass_intro"
	    fi
	
	    echo
	    echo "Hit RETURN to continue"
	    read ans

You should probably retrieve the current environment (which, AFAICT,
requires 5.0 or later; 1.4.2 only appears to allow querying specific
environment variables), and add the GRASS_BATCH_JOB setting to it.

Beyond that, I'd suggest that you abandon the GRASS_BATCH_JOB approach
and set up the environment yourself, without using the grass64 script
at all.

-- 
Glynn Clements <glynn at gclements.plus.com>


More information about the grass-user mailing list