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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
|
public void run() {
System.out.println("Simmetrix starts running");
String [] [b]Cmd={"/disk3/home/mencaglia/develop/cfd-mp/meshParasol/meshParasol-current","-s", "/disk3/home/mencaglia/jbproject/Solver/cas2.msf" };[/b]
for (int i=0; i<3; i++)
System.out.println(Cmd[i]);
try {
Runtime r = Runtime.getRuntime();
/*
Je pense que les 3 lignes suivantes sont inutiles dans notre cas
*/
r.traceInstructions(true);
r.traceInstructions(true);
r.traceMethodCalls(true);
final Process proc = r.exec(Cmd);
new Thread() {
public void run() {
try {
BufferedInputStream errStream =
new BufferedInputStream(proc.getErrorStream());
byte[] buffer = new byte[128];
int read;
while ((read = errStream.read(buffer, 0, buffer.length)) != -1) {
System.err.write(buffer, 0, read);
}
errStream.close();
}
catch (IOException ioe) {
ioe.printStackTrace();
}
}
}.start();
new Thread() {
public void run() {
try {
BufferedInputStream outStream =
new BufferedInputStream(proc.getInputStream());
byte[] buffer = new byte[128];
int read;
while ((read = outStream.read(buffer, 0, buffer.length)) != -1) {
System.out.write(buffer, 0, read);
}
outStream.close();
}
catch (IOException ioe) {
ioe.printStackTrace();
}
}
}.start();
/*
Seulement utile si ton programme lit depuis son entrée standard
FileInputStream inpFile = new FileInputStream(new File("/disk3/home/mencaglia/jbproject/Solver/data.txt"));
final BufferedInputStream input = new BufferedInputStream(inpFile);
new Thread() {
public void run() {
try {
BufferedOutputStream inpStream =
new BufferedOutputStream(proc.getOutputStream());
byte[] buffer = new byte[256];
int read;
while ((read = input.read(buffer, 0, buffer.length)) != -1) {
inpStream.write(buffer, 0, read);
}
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
}.start();
input.close();
inpFile.close();
*/
/*
La fermeture des 3 trois streams me semblent inutiles.
*/
proc.getInputStream().close();
proc.getOutputStream().close();
proc.getErrorStream().close();
int status = proc.waitFor();
//int test = proc.exitValue();
//System.out.println(test);
System.out.println(status);
}
catch (IOException e) {
System.out.println("erreur d'execution " + Cmd + e.toString());
}
catch (InterruptedException e) {
System.out.println("interruption " + Cmd + e.toString());
}
catch (IllegalThreadStateException e)
{
System.out.println("interruption 2" + Cmd + e.toString());
e.printStackTrace();
}
System.out.println("End of run");
} |
Partager