Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 16030

C# console app crashes when running batch file which exist in different directory

$
0
0

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.


Viewing all articles
Browse latest Browse all 16030

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>