Compiling Java code within a C#Builder...

  • Thread starter Thread starter genc ymeri
  • Start date Start date
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.
 
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 !!!!
 
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.
 
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
 
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
 
Back
Top