From: niemisto Date: Tue, 23 Feb 2010 12:38:03 +0000 (+0000) Subject: modelica monitor X-Git-Tag: simantics-1.0~65 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=68f0426eb4f333e5c9cc3074caa0b089b780b73f;p=simantics%2Fsysdyn.git modelica monitor git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@14348 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.modelica/src/org/simantics/modelica/IModelicaMonitor.java b/org.simantics.modelica/src/org/simantics/modelica/IModelicaMonitor.java new file mode 100644 index 00000000..2466983a --- /dev/null +++ b/org.simantics.modelica/src/org/simantics/modelica/IModelicaMonitor.java @@ -0,0 +1,5 @@ +package org.simantics.modelica; + +public interface IModelicaMonitor { + void message(String message); +} diff --git a/org.simantics.modelica/src/org/simantics/modelica/ModelicaManager.java b/org.simantics.modelica/src/org/simantics/modelica/ModelicaManager.java index 72b69ca1..b61f37e7 100644 --- a/org.simantics.modelica/src/org/simantics/modelica/ModelicaManager.java +++ b/org.simantics.modelica/src/org/simantics/modelica/ModelicaManager.java @@ -41,13 +41,13 @@ public class ModelicaManager { return new String(buffer); } - protected static void printProcessOutput(Process process) throws IOException { + protected static void printProcessOutput(Process process, IModelicaMonitor monitor) throws IOException { InputStream stream = process.getInputStream(); while(true) { int c = stream.read(); if(c <= 0) break; - System.out.print((char)c); + monitor.message(new String(new char[] {(char)c})); } } @@ -93,7 +93,8 @@ public class ModelicaManager { ); } - public static SimulationResult runModelica(String modelName, String modelText, Double startTime, Double stopTime) throws IOException { + public static SimulationResult runModelica(String modelName, String modelText, + IModelicaMonitor monitor, Double startTime, Double stopTime) throws IOException { SimulationLocation simulationLocation = createInputFiles(modelName, modelText, startTime, stopTime); @@ -108,7 +109,7 @@ public class ModelicaManager { .directory(simulationLocation.simulationDir.getAbsoluteFile()) .redirectErrorStream(true) .start(); - printProcessOutput(process); + printProcessOutput(process, monitor); SimulationResult result = new SimulationResult(); result.read(simulationLocation.outputFile); @@ -123,14 +124,5 @@ public class ModelicaManager { } return null; } - - public static void main(String[] args) { - try { - runModelica("Testi2", "model Testi2 end Testi2;", 0.0, 10.0); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } }