1

In my code I'm trying to convert a file MDL to file XML using simex as a tool. Then I will use this xml file for some analysis. When I convert this file manually or if i treat a small model (via Process....) ,no error has been occured.

The problem is when I try to convert a big model via Process using this code :

if(!(xmlFile.exists()))
{Process child;

    child = Runtime.getRuntime().exec("cmd.exe /C start /min "+System.getProperty("user.dir")+"\\simex\\MDLtoXML.bat "+path+" "+xmlpath+" " +System.getProperty("user.dir")+"\\simex\\",null,null);
     try {
        child.waitFor();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

This code work good with a small model ,so I think the problem that's my project analyse the xml file before the end of transformation because the error is : Exception in thread "main" org.jdom2.input.JDOMParseExeception:Error on line of document file (......XML):Fin prématurée du fichier............

So I want to know how can wait the end of the transformation then execute the second part of the analyse of xml File.

Nb: I have also tried to put

child.getInputStream().close();
child.getOutputStream().close();

before child.waitFor();

Somaya.

user3446229
  • 95
  • 3
  • 3
  • 14

1 Answers1

1

I think it's the same issue as discussed here: Runtime.exec().waitFor() doesn't wait until process is done

Remove the start parameter to run the shell in foreground not in background mode, so that Java waits for it.

Community
  • 1
  • 1
knoe
  • 644
  • 1
  • 5
  • 16