[Getdp] Launching GetDP from another program

John_V jvillar.john at gmail.com
Thu Dec 2 14:00:53 CET 2010


The problem with launching the batch file turned out to be that Windows 
doesn't natively know how to launch batch files. The operating system 
doesn't know what to make of "FEA.bat", but "cmd /c FEA.bat" works. 
(I.e., launching a batch file is an option of the "cmd" command.) I am 
still not sure why the method I first tried, directly sending "getdp 
-pre EleSta_v.pro -cal", didn't work. I may investigate at some point, 
but doing it via batch file is an acceptable work-around. Thanks to all 
who helped: Joris, Lars, and Ruth.

John


On 12/1/2010 2:48 PM, Joris Goethals wrote:
> 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/20101202/2051fa96/attachment.html>