I have created a console application using C#, and I called it from another Windows Forms application using Process
.
Below is my code for Console Application
static void Main(string[] args)
{
try
{
// ...my code
}
catch (Exception)
{
throw;
}
}
Below is code for call the exe of Console application from the window application using process
public void CallExe()
{
try
{
Process proc = new Process();
proc.StartInfo.FileName = @"D:\Debug\console1.exe";
proc.StartInfo.Arguments = "My args";
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
proc.Start();
proc.WaitForExit();
string stdout = proc.StandardOutput.ReadToEnd();
string stderr = proc.StandardError.ReadToEnd();
proc = null;
}
catch (Exception ex)
{
throw ex;
}
}
Now, What I want is when any error comes from the console application it directly throws to my window application catch block. Or can I get error message to my window application which is thrown by console application ?