By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,919 Members | 1,043 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,919 IT Pros & Developers. It's quick & easy.

Compiling Java code within a C#Builder...

P: n/a
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.

Nov 16 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
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 !!!!

"Ali" <aa*******@gmail.com> wrote in message
news:86**********************************@microsof t.com...
When calling the System.Diagnostics.Process.Start() method, pass it an object of type ProcessStartInfo with the following properties set:

ProcessStartInfo p=new ProcessStartInfo("ConsoleApplication1.exe");
p.RedirectStandardOutput=true;
p.RedirectStandardError=true;
p.UseShellExecute=false;
p.CreateNoWindow=true;
Process ps = Process.Start(p);
this.label1.Text=ps.StandardOutput.ReadLine();

now when the procss starts, it doesnot have a window (so no console window) and all the output to the standard output and standard error stream are
redirected to the ps.StandardOutput stream and can be read using any of the stream access mechenisms (such as ReadLine being used in the above sample).
Hope this helps

Ali Gardezi

Nov 16 '05 #2

P: n/a
genc ymeri <ge********@hotmail.com> wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #3

P: n/a
Yeap, it works reading standart errors.

Thanks a lot Ali & Jon :) :)

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
genc ymeri <ge********@hotmail.com> wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #4

P: n/a
Ali
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

"genc ymeri" wrote:
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 !!!!

"Ali" <aa*******@gmail.com> wrote in message
news:86**********************************@microsof t.com...
When calling the System.Diagnostics.Process.Start() method, pass it an

object
of type ProcessStartInfo with the following properties set:

ProcessStartInfo p=new ProcessStartInfo("ConsoleApplication1.exe");
p.RedirectStandardOutput=true;
p.RedirectStandardError=true;
p.UseShellExecute=false;
p.CreateNoWindow=true;
Process ps = Process.Start(p);
this.label1.Text=ps.StandardOutput.ReadLine();

now when the procss starts, it doesnot have a window (so no console

window)
and all the output to the standard output and standard error stream are
redirected to the ps.StandardOutput stream and can be read using any of

the
stream access mechenisms (such as ReadLine being used in the above

sample).

Hope this helps

Ali Gardezi


Nov 16 '05 #5

P: n/a
thanks a lot :) :)
"Ali" <aa*******@gmail.com> wrote in message
news:E4**********************************@microsof t.com...
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

"genc ymeri" wrote:
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 !!!!

"Ali" <aa*******@gmail.com> wrote in message
news:86**********************************@microsof t.com...
When calling the System.Diagnostics.Process.Start() method, pass it an

object
of type ProcessStartInfo with the following properties set:

ProcessStartInfo p=new ProcessStartInfo("ConsoleApplication1.exe");
p.RedirectStandardOutput=true;
p.RedirectStandardError=true;
p.UseShellExecute=false;
p.CreateNoWindow=true;
Process ps = Process.Start(p);
this.label1.Text=ps.StandardOutput.ReadLine();

now when the procss starts, it doesnot have a window (so no console

window)
and all the output to the standard output and standard error stream are redirected to the ps.StandardOutput stream and can be read using any
of the
stream access mechenisms (such as ReadLine being used in the above

sample).

Hope this helps

Ali Gardezi


Nov 16 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.