Executing a Java Program from Windows Application using c#

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
I am developing a Windows Application in C# for compiling and executing any java program.
I have used System.Diagnostics. Well, the problem is that, compile works properly (it creates a .class file which I then execute using command prompt and it works!) but when I try to run the program from the Windows application itself, it does not display
the output.
Here is the code for Run:
<pre class="prettyprint ProcessStartInfo processStartInfo = new ProcessStartInfo("C:\Program Files\Java\jdk1.6.0_30\bin\java.exe");
processStartInfo.WorkingDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
processStartInfo.Arguments = "HelloWorld";
processStartInfo.UseShellExecute = false;
processStartInfo.ErrorDialog = false;
processStartInfo.RedirectStandardError = true;
processStartInfo.RedirectStandardInput = true;
processStartInfo.RedirectStandardOutput = true;

Process process = new Process();
process.StartInfo = processStartInfo;
bool processStarted = process.Start();
process.WaitForExit();

StreamWriter inputWriter = process.StandardInput;
StreamReader outputReader = process.StandardOutput;
StreamReader errorReader = process.StandardError;

String error_string = errorReader.ReadToEnd();
textPad.AppendText(error_string+"");
textPad.AppendText("OUTPUT:nn");
String output_string = outputReader.ReadToEnd();
textPad.AppendText(output_string);[/code]
<br/>
Well, I kind of displayed the output in a richtextbox (i.e, textPad) but how can I display the output in the Command Prompt itself?
The cmd window is shown momentarily and then it disappears.
Please help. Your valuable comments will be acknowledged. Thank you.

View the full article
 
Back
Top