|
View:
New views
1 Messages
—
Rating Filter:
Alert me
|
|
|
Stream of a process does not seam to be correctly redirectedUh,
probably I should paste the code right here: This is my test-class: package main; public class Test { /** * @param args */ public static void main(String[] args) { System.out.println("Hello world"); } } And here comes the part using the Java Debug Interface: import java.io.IOException; import java.io.InputStream; import java.util.Iterator; import java.util.List; import java.util.Map; import com.sun.jdi.Bootstrap; import com.sun.jdi.VirtualMachine; import com.sun.jdi.VirtualMachineManager; import com.sun.jdi.connect.Connector; import com.sun.jdi.connect.LaunchingConnector; import com.sun.jdi.connect.Connector.Argument; public class TestVmProcess { private static VirtualMachine _vm; private static VirtualMachineManager _vmManager; private static LaunchingConnector _connector; /** * @param args */ public static void main(String[] args) throws Exception { // vm manager _vmManager = Bootstrap.virtualMachineManager(); // connector List<Connector> connectors = _vmManager.allConnectors(); Iterator<Connector> iterator = connectors.iterator(); while (iterator.hasNext()) { Connector c = iterator.next(); { _connector = (LaunchingConnector) c; break; } } // arguments Map<String, Argument> arguments = _connector.defaultArguments(); Argument arg = (Argument) arguments.get("main"); arg.setValue("main.Test"); arg = (Argument) arguments.get("home"); System.out.println("--> JAVA_HOME = " + arg.value()); // manually set this path as under ikvm i get '.virtual-ikvm-home' arg.setValue("C:/Java/jdk1.6.0_17"); // launch vm _vm = _connector.launch(arguments); // redirect output of the vm Thread streamReader = new Thread(new Runnable(){ @Override public void run() { InputStream stream = _vm.process().getInputStream(); while(true) { try { if (stream.available() > 0) { System.out.println("--> someting was printed out"); break; } } catch (IOException e) { break; } } System.out.println("streamReader done"); }}); streamReader.start(); // keep the vm running Thread vmRunner = new Thread(new Runnable(){ @Override public void run() { while(true) { try { _vm.eventQueue().remove().resume(); } catch (Exception e) { break; } } System.out.println("vmThread done"); }}); vmRunner.start(); // keep running until user presses a button System.in.read(); } } Sorry for that! Markus ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ Ikvm-developers mailing list Ikvm-developers@... https://lists.sourceforge.net/lists/listinfo/ikvm-developers |
| Free embeddable forum powered by Nabble | Forum Help |