Compiling Java code within a C#Builder...

G

genc ymeri

Hi overthere,
I'm trying to compile some Java code within a C# application form. So the
end user will write his/her code in a textbox and a button compile will
compiles it.

I tried to use System.Diagnostics.Process.Start() but the console
application was launched too.
I want to compile and retrieve the errors/messages without lauching another
app and showing the errors/messages in within my winform.

Any tip will be very much appreciated.

Thank You in advance.
 
G

genc ymeri

Ali,
It seems that it is working in the background but I'm not able to read out
the messages. Am I doing something wrong ????

ProcessStartInfo p = new ProcessStartInfo("C:\\javac.exe",
"C:\\Hello.java");
p.RedirectStandardOutput=true;
p.RedirectStandardError=true;
p.UseShellExecute=false;
p.CreateNoWindow=true;
Process ps = Process.Start(p);
this.label1.Text=ps.StandardOutput.ReadLine(); //reads nothing...??


When I run it from the console I get these error messages:

C:\javac.exe Hello.java

Hello.java:3: invalid method declaration;
return type required
public sayHello()
^
Hello.java:5: write(java.lang.String) has
private access in java.io.PrintStream
System.out.write("hello");
^
2 errors




Thanks a lot !!!!
 
J

Jon Skeet [C# MVP]

genc ymeri said:
It seems that it is working in the background but I'm not able to read out
the messages. Am I doing something wrong ????

ProcessStartInfo p = new ProcessStartInfo("C:\\javac.exe",
"C:\\Hello.java");
p.RedirectStandardOutput=true;
p.RedirectStandardError=true;
p.UseShellExecute=false;
p.CreateNoWindow=true;
Process ps = Process.Start(p);
this.label1.Text=ps.StandardOutput.ReadLine(); //reads nothing...??

Have you tried reading from StandardError instead of StandardOutput?
After all, those are error messages.
 
G

Guest

Error messages are sent to standard error, thats why i have also redirected
standard error in the given code. So instead of doing
ps.StandardOutput.ReadLine(); to read error messages, use
ps.StandardError.ReadLine(); to see if the compiler returned error messages.

Ali Gardezi
 
G

genc ymeri

thanks a lot :) :)
Ali said:
Error messages are sent to standard error, thats why i have also redirected
standard error in the given code. So instead of doing
ps.StandardOutput.ReadLine(); to read error messages, use
ps.StandardError.ReadLine(); to see if the compiler returned error messages.

Ali Gardezi
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top