commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maven apache <apachemav...@gmail.com>
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
/home/kk/grass/GrassDataBase/spearfish60/PERMANENT
System.out.println("start line=="+line.toString());
 DefaultExecutor de=new DefaultExecutor();
try {
int index=de.execute(line,env);
 System.out.println(index);
} catch (ExecuteException e) {
e.printStackTrace();
 } catch (IOException e) {
e.printStackTrace();
}
 }
public static void main(String[] args) {
String jobPath=Grass.class.getResource("grass.sh").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"
--------------------
java.io.IOException: Cannot run program "grass64 -text
/home/kk/grass/GrassDataBase/spearfish60/PERMANENT": java.io.IOException:
error=2, No such file or directory
 at java.lang.ProcessBuilder.start(ProcessBuilder.java:459)
at java.lang.Runtime.exec(Runtime.java:593)
 at
org.apache.commons.exec.launcher.Java13CommandLauncher.exec(Java13CommandLauncher.java:58)
at org.apache.commons.exec.DefaultExecutor.launch(DefaultExecutor.java:246)
 at
org.apache.commons.exec.DefaultExecutor.executeInternal(DefaultExecutor.java:302)
at org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:149)
 at org.kingxip.Grass.run(Grass.java:27)
at org.kingxip.Grass.main(Grass.java:38)
Caused by: java.io.IOException: java.io.IOException: error=2, No such file
or directory
at java.lang.UNIXProcess.<init>(UNIXProcess.java:148)
 at java.lang.ProcessImpl.start(ProcessImpl.java:65)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:452)
 ... 7 more
--------------------
I wonder why?

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