commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maven apache <>
Subject Fwd: common exec
Date Wed, 03 Mar 2010 05:56:46 GMT
I meet a strange problem, a cmd can be executed in the command line ,however
can not be in the code using common exec. codes are:
public class Grass {
public static String grassBatJob="GRASS_BATCH_JOB";
public void run(String cmd,String jobPath) {
 //set the environments variables
Map<String, String> env=new HashMap<String, String>();
 env.put(grassBatJob, jobPath);
 String gisDataBase="/home/kk/grass/GrassDataBase";
 String location="spearfish60";
String mapset="PERMANENT";
 cmd=cmd+" "+gisDataBase+"/"+location+"/"+mapset;
CommandLine line=new CommandLine(cmd);
 //the real cmd should be >>grass64 -text
System.out.println("start line=="+line.toString());
 DefaultExecutor de=new DefaultExecutor();
try {
int index=de.execute(line,env);
} catch (ExecuteException e) {
 } catch (IOException e) {
public static void main(String[] args) {
String jobPath=Grass.class.getResource("").getFile();
 new Grass().run("grass64 -text", jobPath);
The real cmd I want to execute is "grass64 -text
/home/kk/grass/GrassDataBase/spearfish60/PERMANENT" with the envrionment
variable "GRASS_BATCH_JOB=jobPath",it works well in the ternimal ,however in
my application I got the exception"
-------------------- Cannot run program "grass64 -text
error=2, No such file or directory
 at java.lang.ProcessBuilder.start(
at java.lang.Runtime.exec(
at org.apache.commons.exec.DefaultExecutor.launch(
at org.apache.commons.exec.DefaultExecutor.execute(
at org.kingxip.Grass.main(
Caused by: error=2, No such file
or directory
at java.lang.UNIXProcess.<init>(
 at java.lang.ProcessImpl.start(
at java.lang.ProcessBuilder.start(
 ... 7 more
I wonder why?

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message