Executing a Java Program from Windows Application using c#

  • Thread starter Thread starter Rohan Cambel
  • Start date Start date
R

Rohan Cambel

Guest
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:

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:\n\n");
String output_string = outputReader.ReadToEnd();
textPad.AppendText(output_string);


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.

Continue reading...
 
Back
Top