Stream of a process does not seam to be correctly redirected

View: New views
4 Messages — Rating Filter:   Alert me  

Stream of a process does not seam to be correctly redirected

by Markus Bischof-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi all,

this is my first time writing to this list, so I hope I'm targeting the correct audience.

I've developed a Java application which uses the Java Debug Interface (comes in the tools.jar-file of each Java SDK lib folder). The application starts a Java virtual machine and executes the given java program.

After some time I thought it might be very cool to have this application as a .NET assembly. I converted my jar-file (as well as the tools.jar) and most functionality worked really fine. Although ikvmc could not convert the whole tools.jar-file, it was enough for my program to run.
 
But I ran into a problem with reading out the output stream of the virtual machine process (reading out a stream from a process created on my own is actually no problem in the converted exe). 

I've added a small program showing this problem. I've also added the test file I'm using. 

To execute the program in eclipse, you have to reference the tools.jar and also set the working directory of the program to be the folder where your binaries are located (the compiled test file must be located in the subdirectory "main"). When you run the program, you will get an output similiar to:

--> JAVA_HOME = C:\Program Files\Java\jre6
--> someting was printed out
streamReader done
vmThread done


After converting the jar file to a .NET exe file (and placing it into the same directory), I only got the output:

--> JAVA_HOME = C:\.virtual-ikvm-home
vmThread done


This reveals two differences:
1. Somehow the functionality of how the value of JAVA_HOME is obtained is differently (this is no environment variable, actually. Because it's not my java code, I can't say how the value is obtained). In the test application, I override this value with the correct path to be sure that the .NET exe has set the correct path.
2. It seems that reading from the output stream of the virtual machine process is not possible. There is no line indicating that stream.available() returns true. This is actually the bigger problem.

Well, I hope someone might know a solution for my problem(s)! I also hope that the sample program is simple enough to be understandable.

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

Test.java (270 bytes) Download Attachment
TestVmProcess.java (3K) Download Attachment

Re: Stream of a process does not seam to be correctlyredirected

by Volker Berlin :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Markus,
 
What do you want do with the Java Debug Interface? If you want start an external process then it is simpler to use java.lang.Process.
 
Because IKVM does not implement the Java Debug Intererface that you can't debug a IKVM process currently with a Java IDE. It can be possible that if you use tools.jar that you can debug an real Java process with a IKVM application. This part of JDI is 100% pure Java.
 
I think the problem is that the external process was not startet. That you can not receive a stream. You test application sould create a file or equals that you see that it was running.
 
Volker


Von: Markus Bischof [mailto:markusbischof82@...]
Gesendet: Montag, 9. November 2009 19:36
An: ikvm-developers@...
Betreff: [Ikvm-developers] Stream of a process does not seam to be correctlyredirected

Hi all,

this is my first time writing to this list, so I hope I'm targeting the correct audience.

I've developed a Java application which uses the Java Debug Interface (comes in the tools.jar-file of each Java SDK lib folder). The application starts a Java virtual machine and executes the given java program.

After some time I thought it might be very cool to have this application as a .NET assembly. I converted my jar-file (as well as the tools.jar) and most functionality worked really fine. Although ikvmc could not convert the whole tools.jar-file, it was enough for my program to run.
 
But I ran into a problem with reading out the output stream of the virtual machine process (reading out a stream from a process created on my own is actually no problem in the converted exe). 

I've added a small program showing this problem. I've also added the test file I'm using. 

To execute the program in eclipse, you have to reference the tools.jar and also set the working directory of the program to be the folder where your binaries are located (the compiled test file must be located in the subdirectory "main"). When you run the program, you will get an output similiar to:

--> JAVA_HOME = C:\Program Files\Java\jre6
--> someting was printed out
streamReader done
vmThread done


After converting the jar file to a .NET exe file (and placing it into the same directory), I only got the output:

--> JAVA_HOME = C:\.virtual-ikvm-home
vmThread done


This reveals two differences:
1. Somehow the functionality of how the value of JAVA_HOME is obtained is differently (this is no environment variable, actually. Because it's not my java code, I can't say how the value is obtained). In the test application, I override this value with the correct path to be sure that the .NET exe has set the correct path.
2. It seems that reading from the output stream of the virtual machine process is not possible. There is no line indicating that stream.available() returns true. This is actually the bigger problem.

Well, I hope someone might know a solution for my problem(s)! I also hope that the sample program is simple enough to be understandable.

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

Parent Message unknown Re: Stream of a process does not seam to be correctlyredirected

by Volker Berlin :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Markus,
 
I think there can be 2 causes for the problem:
1.) You write that not all was compiled without problems. Which problems occur?
2.) You use a part from the Sun JDK (tools.jar). This must not be compatible with the OpenJDK. There are some changes in some internal packages..
 
We can add the some of the needed sources to the IKVM and add a IKVM.OpenJDK.tools.dll.
 
Volker


Von: Markus Bischof [mailto:markusbischof82@...]
Gesendet: Montag, 9. November 2009 20:46
An: Volker Berlin
Betreff: Re: AW: [Ikvm-developers] Stream of a process does not seam to be correctlyredirected

Hi Volker,

thanks for your quick reply.

Well, my intention is to be able to debug an arbitrary java application within a .NET control, for example, a specialized TextBox. For that purpose, I need to access the java application using the Java Debug Interface.

My actual implementation in Java uses the Java Debug Interface and implements a facade around it. Clients (in my case the TextBox) only need to provide a very simple interface to debug a java application (at least some parts of it). 


I added the following lines to my sample program:

File f = new File("JavaWasHere");
f.createNewFile();

After compiling the sample program (using the standard java compiler), copying the class-file into the correct directory and running the exe-file, I really see the file being created. So the process was started and did succeed. Only the code which reads out the output stream of the process does not seem to get the "Hello world" output. 

--> Running the java implementation, the file gets created, too, and the "Hello world" from the sample program is received.

I really think there is a problem in the conversion process from java to .NET...

Markus

Am 09.11.2009 um 20:19 schrieb Volker Berlin:

Hi Markus,
 
What do you want do with the Java Debug Interface? If you want start an external process then it is simpler to use java.lang.Process.
 
Because IKVM does not implement the Java Debug Intererface that you can't debug a IKVM process currently with a Java IDE. It can be possible that if you use tools.jar that you can debug an real Java process with a IKVM application. This part of JDI is 100% pure Java.
 
I think the problem is that the external process was not startet. That you can not receive a stream. You test application sould create a file or equals that you see that it was running.
 
Volker


Von: Markus Bischof [mailto:markusbischof82@...]
Gesendet: Montag, 9. November 2009 19:36
An: ikvm-developers@...
Betreff: [Ikvm-developers] Stream of a process does not seam to be correctlyredirected

Hi all,

this is my first time writing to this list, so I hope I'm targeting the correct audience.

I've developed a Java application which uses the Java Debug Interface (comes in the tools.jar-file of each Java SDK lib folder). The application starts a Java virtual machine and executes the given java program.

After some time I thought it might be very cool to have this application as a .NET assembly. I converted my jar-file (as well as the tools.jar) and most functionality worked really fine. Although ikvmc could not convert the whole tools.jar-file, it was enough for my program to run.
 
But I ran into a problem with reading out the output stream of the virtual machine process (reading out a stream from a process created on my own is actually no problem in the converted exe). 

I've added a small program showing this problem. I've also added the test file I'm using. 

To execute the program in eclipse, you have to reference the tools.jar and also set the working directory of the program to be the folder where your binaries are located (the compiled test file must be located in the subdirectory "main"). When you run the program, you will get an output similiar to:

--> JAVA_HOME = C:\Program Files\Java\jre6
--> someting was printed out
streamReader done
vmThread done


After converting the jar file to a .NET exe file (and placing it into the same directory), I only got the output:

--> JAVA_HOME = C:\.virtual-ikvm-home
vmThread done


This reveals two differences:
1. Somehow the functionality of how the value of JAVA_HOME is obtained is differently (this is no environment variable, actually. Because it's not my java code, I can't say how the value is obtained). In the test application, I override this value with the correct path to be sure that the .NET exe has set the correct path.
2. It seems that reading from the output stream of the virtual machine process is not possible. There is no line indicating that stream.available() returns true. This is actually the bigger problem.

Well, I hope someone might know a solution for my problem(s)! I also hope that the sample program is simple enough to be understandable.

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

Parent Message unknown Re: Stream of a process does not seam to be correctlyredirected

by Volker Berlin :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Markus,
 
After looking deeper in the problem I have some results but not a solution. I hope this help you to find a solution. The command line from Java VM and from IKVM are different. The Java VM use shared memory and IKVM used a socket listener. The command lines look like:
 
C:/Programme/Java/jre6\bin\java -Xdebug -Xrunjdwp:transport=dt_shmem,address=javadebug59541,suspend=y main.Test
C:/Programme/Java/jre6\bin\java -Xdebug -Xrunjdwp:transport=dt_socket,address=myComputer:2330,suspend=y main.Test
 
You can test the socket listener with Java if you remove the class com.sun.tools.jdi.SharedMemoryTransportService. After I have adding some debug code I have in Eclipse the same problem with Java. That I think there is also a timimg problem. If you call read() instead of available() then you receive the output from the process also in IKVM.
 
In the .NET documenation http://msdn.microsoft.com/en-us/library/system.io.filestream.canseek%28VS.80%29.aspx you can read that a FileStream from a Console does not support CanSeek. That it is not possible to calc an available. Are you sure that this has work with Runtime.exec? This API use also Runtime.exec which you see on the stacktrace if you use an invalid path. I have not test it self.
 
Volker
 


Von: Markus Bischof [mailto:markusbischof82@...]
Gesendet: Dienstag, 10. November 2009 21:23
An: Volker Berlin
Betreff: Re: [Ikvm-developers] Stream of a process does not seam to be correctlyredirected

Hi Volker,

I've added my output from the conversion. You see that I'm calling 

ikvmc -target:library DebuggingInterface.jar tools.jar

and that I first get some "missing class" warnings. At the end I get many warnings that classes are skipped.

I don't know it these warnings are related to my problem that I cannot read the inputstream of the process. 

Please notice that I've implemented a small java program which starts a process (e.g. Runtime.getRuntime.exec(...java.exe)) and reads out the inputstream of this process (printing out the usage of java...). This small program converted to .NET works fine...looking at the code which reads out the stream, it looks exactly like the code which tries to read out the inputstream in my sample program. The only difference is that I do not start the process by myself. I'm really very confused how to investigate this problem by myself...

Is there any information I can provide you to get a better understanding of my problem? If you have the time, maybe you can try to run my sample program in eclipse as well as use ikvm to convert the file and run it with .NET to reconstruct the problem...

Your help is much appreciated!

Regards,
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