I have a batch file, which I need to run from my c# application. Batch file location is different from my c# console app exe location.I'm trying below code, my c# console app crashes after calling Process.WaitForExit(), it is not even going to catch block.
Note : batch file ran successfully and produced expected result, but my c# application is crashing.
try { var processInfo = new ProcessStartInfo("cmd.exe", "/c " + batfile.bat); processInfo.CreateNoWindow = true; processInfo.WorkingDirectory = "location of batfile.bat"; processInfo.UseShellExecute = false; var process = Process.Start(processInfo); process.WaitForExit(); if (process.ExitCode == 1) isSuccessful = true; process.Close(); } catch(Exception ex) { //log }
I tried above method but it keeps on crashing.