[Getdp] Launching GetDP from another program
Joris Goethals
joris.goethals at gmail.com
Wed Dec 1 20:48:31 CET 2010
Hi there,
In my program, I used this code to launch GetDP:
First I used an array of command and parameters, but that gave me the same
CreateProcess error.
Now I put every command in a String.format(), and execute it with the
following method:
private void executeCommand(String cmd) {
try {
if(cmd ==null){
notifyListeners("Kan het commando niet uitvoeren", ERROR);
}
Runtime rt = Runtime.getRuntime();
if (workDir == null) {
notifyListeners("De werkmap is nog niet ingesteld", Infobalie.ERROR);
throw new NullPointerException("Werkmap nog niet ingesteld");
}
System.out.printf("Uitvoeren van commando %s\n", cmd);
Process p = rt.exec(cmd, null, workDir);
InputStream std = p.getInputStream();
InputStreamReader isr = new InputStreamReader(std);
BufferedReader br = new BufferedReader(isr);
String line = null;
while ((line = br.readLine()) != null){
notifyListeners(line, (line.startsWith("Warning")?ERROR:NEUTRAAL));
}
int exitvalue = p.waitFor();
notifyListeners(String.format(
"Commando uitgevoerd met exitwaarde %d.", exitvalue),
Infobalie.SUCCESS);
} catch (IOException ioe) {
System.out.println(ioe.getMessage());
ioe.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
This method is called by
public void pre(int pre) {
String command = null;
try {
command = String.format("%s %s -msh %s -pre %s",
getDpExe.getPath(), problemDefinition.getPath(), geo.getPath(),
resolutieLijst.get(pre));
} catch (NullPointerException npe) {
notifyListeners("Niet genoeg parameters om commando uit te voeren",
ERROR);
return;
}
executeCommand(command);
}
public void cal() {
String command = null;
try {
command = String.format("%s %s -msh %s -cal",
getDpExe.getPath(), problemDefinition.getPath(), geo.getPath());
} catch (NullPointerException npe) {
notifyListeners("Niet genoeg parameters om commando uit te voeren",
ERROR);
return;
}
executeCommand(command);
}
public void pos(int post) {
String command = null;
try {
command = String.format("%s %s -msh %s -pos %s",
getDpExe.getPath(), problemDefinition.getPath(), geo.getPath(),
postCalculationLijst.get(post));
} catch (NullPointerException npe) {
notifyListeners("Niet genoeg parameters om commando uit te voeren",
ERROR);
return;
}
executeCommand(command);
}
Good luck with it!
Joris
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.geuz.org/pipermail/getdp/attachments/20101201/c437198c/attachment.html>