1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
private void callExec (String [] cmd, String env)
{
try
{
Runtime rt = Runtime.getRuntime() ;
String temp = "";
for (int i = 0 ; i < cmd.length ; i++)
{
System.out.println("temp = " + cmd[i]);
temp += cmd[i];
}
System.out.println("Env = " + env);
System.out.println("cmd = " + temp);
Process proc = rt.exec(cmd, null, new File(env) ) ;
java.io.InputStream stdin = proc.getInputStream () ;
java.io.InputStream stderr = proc.getErrorStream();
InputStreamReader isr = new InputStreamReader (stdin) ;
InputStreamReader isrerr = new InputStreamReader (stderr) ;
BufferedReader br = new BufferedReader (isr) ;
BufferedReader brerr = new BufferedReader (isrerr) ;
String line = null ;
while ( (line = br.readLine()) != null)
System.out.println(line) ;
while ( (line = brerr.readLine()) != null)
System.out.println(line) ;
// Mise en attente tant que le process n'est pas termine.
int exitVal = proc.waitFor() ;
if (exitVal != 0)
{ // Si la simulation s'est mal deroule, alors on fait remonter l'exception et on quitte
throw new Exception ("\n \n Exit Process... \n \n") ;
}
}
catch (IOException ioex)
{
System.out.println("Hapke process IOException exception");
System.out.println (ioex.getMessage ()) ;
ioex.printStackTrace () ;
System.exit(1) ;
}
catch (Exception ex)
{
System.out.println (ex.getMessage ()) ;
ex.printStackTrace () ;
System.exit(1) ;
}
} |
Partager