So what i am doing is calling java.exe and making a call to a jar file with some arguments. If everyting is fine and the command works, then the arguments are printed out to a richtext box.
The issue I am having is when the command isn't correct. So in once instance, say the user types in the wrong password that's passed into txtPassword. Stanadard out is not being redirected. If i run the exact same command in a Dos console, the message "Error: Auth fail", is being presented. How do i redirect that error to the rich text box? I thought redirecting stdout would do it, but apparently not.
Any help would be apprecaited. Please see the code below.
//Declare and instantiate a new process component.
System.Diagnostics.Process process1;
process1 = new System.Diagnostics.Process();
process1.StartInfo.UseShellExecute = false;
process1.StartInfo.RedirectStandardOutput = true;
process1.StartInfo.CreateNoWindow = true;
process1.StartInfo.FileName = "java.exe ";
toLoad = lstBarToLoad.Items[i].Text;
process1.StartInfo.Arguments = "-Xmx512M -jar Deploy.jar" + txtPassword;
process1.StartInfo.Arguments += toLoad;
Console.WriteLine(process1.StartInfo.Arguments);
process1.Start();
process1.OutputDataReceived += (s, a) => myMethod(a);
process1.BeginOutputReadLine();
//myMthod
private void myMethod(DataReceivedEventArgs e)
{
if (e.Data != null)
{
Action action = () => rchsdtOut.Text += "\r\n" + e.Data.ToString();
rchsdtOut.BeginInvoke(action, null);
Console.WriteLine(e.Data.ToString());
}
}//end of private
As well as using
You also need to use
http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.redirectstandarderror.aspx
You can then read out the error and do with it as you please: