I have a windows form application and a command prompt exe. I'm executing the command prompt whithin win form button click
ProcessStartInfo info = new ProcessStartInfo();
info.FileName = "ConsoleApplication2.exe";
Process.Start(info);
And i have some operation whtin button click event which is executed after calling the exe. But i will only need to perform if there is no exception thrown from command prompt exe. Basically what is need is to bubble up the exception from exe to win from. I tried throwing the exception but since both exe and win from are two different application instances exception is not thrown back to caller. Is there any way to achieve this ?
Your code activate an exe file. notice that your program, like every other program is returning a code. this return code can be achieved by doing:
ProcessStartInfo info = new ProcessStartInfo();
info.FileName = "ConsoleApplication2.exe";
Process p = Process.Start(info);
p.WaitForExit();
int eCode = p.ExitCode;
please do not do that in the main thread because it will stop until the process is stopped.
in your ConsoleApplication2.exe make sure that in case of exception you'll return ( in the main function) a code(number) indicating there was an error. it is that simple:
static int Main()
{
try
{
// My code
}
catch (Exception)
{
return 5;// Meaning error
}
return 0; // all went better then expected!
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With