<br>Hi, thanks for your detailed reply.<br>And I have write a java class according to your instruction,however it can not give the right output. I test with the spearfish60 data and the <a href="http://r.info">r.info</a> process.<br>
Attach my code, can you check it ?<br>Thanks anyway.<br><div class="gmail_quote">2010/3/5 Glynn Clements <span dir="ltr"><<a href="mailto:glynn@gclements.plus.com">glynn@gclements.plus.com</a>></span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="im"><br>
maven apache wrote:<br>
<br>
> > > So, what is the problem?<br>
> ><br>
> > With java.lang.Runtime.exec(String cmd, String[] envp), the envp<br>
> > parameter specifies the entire environment for the process (i.e. it<br>
> > doesn't add the strings to the current process' environment). The<br>
> > result is that HOME isn't set, which means that $HOME/.grassrc6 cannot<br>
><br>
> I can not understand, my grass command is "grass64 -text<br>
> /home/kk/grass/GrassDataBase/spearfish60/PERMANENT", so I have specified the<br>
> location and mapset, the gisrc file is required at any times?<br>
<br>
</div>The grass64 script creates a copy of $HOME/.grassrc6 and sets GISRC to<br>
refer to the copy. If $HOME/.grassrc6 doesn't exist, the copy won't<br>
exist either, and the first-use screen will be shown.<br>
<div class="im"><br>
> > Beyond that, I'd suggest that you abandon the GRASS_BATCH_JOB approach<br>
> > and set up the environment yourself, without using the grass64 script<br>
> > at all.<br>
><br>
> God!, in fact I tied to set up the env vars by myself, however many people<br>
> suggest me to use the grass_batch _job for easily using. Now I can not make<br>
> a choice.<br>
> Here I can show you my requirements, can you give me some advise?<br>
> ---my requirements----<br>
><br>
> I am working with the Web Processing Service, and I want to wrap some grass<br>
> operation ( for example the buffer , the interpolation and ect...) as<br>
> processes in the web service, And my web application is developed by java. I<br>
> changed my work platform from win xp to ubuntu beacuase of the unexpected<br>
> errors when I call the grass command(Actually I can not do the interpolation<br>
> operation in the windows-xp command line, but it can work in the Ubuntu<br>
> shell).<br>
> I have a general idea:<br>
> Create a class named GrassManager, and it contain a method to set the env (a<br>
> gisrc file for each user) and a method to call the concrete grass command<br>
> (for example <a href="http://r.info" target="_blank">r.info</a> .....) basing on the set env.<br>
><br>
> However I need to solve the following problems:<br>
> 1) how to set up the grass env in java?<br>
<br>
</div>As for what variables need to be set, refer to:<br>
<br>
1. My answer to your previous post in the thread "grass env".<br>
<br>
2. The thread "can I access mapset outside of grass, by using python?"<br>
by Nikos Alexandris.<br>
<br>
3. The variables.html file in the GRASS distribution.<br>
<br>
You first need to make a copy of the existing environment, then add or<br>
replace any environment settings required by GRASS.<br>
<div class="im"><br>
> 2) after set up the env ,how to call the grass command in java, because it<br>
> reffed to command interpreter and separate executable, I do not know the<br>
> grass command is either?<br>
<br>
</div>Once you have created the environment, I suggest using:<br>
<br>
Java.lang.Runtime.exec(String[] cmdarray, String[] envp)<br>
or:<br>
Java.lang.Runtime.exec(String[] cmdarray, String[] envp, File dir)<br>
<br>
for each GRASS command. The versions which take the command as a<br>
single string are problematic if an argument contains spaces.<br>
<div class="im"><br>
> 3) As a web application, I should consider the multiple user situation,<br>
> create a unique gisrc file for each user?<br>
<br>
</div>Ideally, you should use a separate $GISRC file and a separate mapset<br>
for each session. If you use a single mapset, the WIND and VAR files<br>
will be shared by all sessions. The VAR file probably won't be an<br>
issue (it only holds the database connection information). You can get<br>
around the WIND issue by setting WIND_OVERRIDE to the name of a<br>
specific region (created with e.g. "g.region save=..."), which will be<br>
used instead of the WIND file.<br>
<br>
But the main thing for a web application is to validate all inputs.<br>
Don't pass values from form fields directly to commands, as the code<br>
uses fixed-size buffers extensively and doesn't perform bounds<br>
checking. Also, shell scripts (and some compiled programs which use<br>
system() or popen()) may misbehave if arguments contain shell<br>
metacharacters.<br>
<font color="#888888"><br>
--<br>
</font><div><div></div><div class="h5">Glynn Clements <<a href="mailto:glynn@gclements.plus.com">glynn@gclements.plus.com</a>><br>
</div></div></blockquote></div><br>