473,405 Members | 2,160 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Compiling Java code within a C#Builder...

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
5 2043
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Brian | last post by:
I am having alot of trouble getting a XML document validated with a schema. I got a sample document and schema off of w3schools.com, which passed an online xml validator:...
0
by: Raphael A. Bauer | last post by:
Hi, I am just using this Java code: ---------- //Read it => automatically converts it to UTF-8 DocumentBuilderFactory factory = DocumentBuilderFactory .newInstance(); DocumentBuilder...
11
by: DrUg13 | last post by:
In java, this seems so easy. You need a new object Object test = new Object() gives me exactly what I want. could someone please help me understand the different ways to do the same thing in...
3
by: Rhino | last post by:
I've spent the last couple of hours trying to figure out how to debug a Java stored procedure and am just going in circles. The last straw came when I got "Cannot open input stream for default"...
2
by: Michael | last post by:
Running DB2 v7 UDB ("DB2 v7.1.0.93", "n031208" and "WR21333") on Windows XP, I am unable to find out why the "Build for Debug" option within Stored Procedure Builder is not enabled on Java stored...
10
by: surabhi | last post by:
A while ago I evaluated Eclipse vs Visual Studio, and settled on Visual Studio 2005. Eclipse is better in many ways, but the lack of a gui builder was the deciding factor. Visual Studio 2005 has an...
7
by: maya | last post by:
hi, I'm following example 'Intro7.aspx' here, http://www.csharpfriends.com/quickstart/aspplus/doc/webformsintro.aspx#customctrls it says on top of Acme.cs "namespace Acme" I assume this means...
2
by: KyleUbenk | last post by:
Hello, I am attempting to compile java code from within my program. Basically I have a file in the directory with Java source code, and I want to be able to compile it from within my program. The...
5
by: hussainsaiger | last post by:
I am trying to convert a python module (that contains the use of NLTK.Corpus) by jythonc. It is not able to include nltk dependencies within the java class it creates. So when i use this class in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.