![]() If you HAVE to go the batch script route, make sure that the batch script set exitcode properly. I use it in a number of projects and it works like a charm. Throw new Exception(String.Format("Process '", String output = p.StandardOutput.ReadToEnd() Must have the readToEnd BEFORE the WaitForExit(), to avoid a deadlock condition Cannot set priority process is started. P.StartInfo.WorkingDirectory = currentDirectory If (!String.IsNullOrEmpty(currentDirectory)) P.StartInfo.RedirectStandardError = true ![]() P.StartInfo.RedirectStandardOutput = true P.StartInfo.WindowStyle = ProcessWindowStyle.Hidden If (String.IsNullOrEmpty(binaryFilename)) Public static string ExecuteProcess(string binaryFilename, string arguments, string currentDirectory, ProcessPriorit圜lass priorit圜lass) It is much easier to run the process directly instead of using creating a batch file that you later execute since you lose some control since you are using a batch script layer. So far Ive tried using the exit command within the batch file to close the cmd window (I also have a shortcut on the desktop) but it doesnt seem to work: tncserver.exe C:Work -p4 -b57600 -r -cFE -tTNC426B exit. procStartInfo new ('cmd', '/c ' + command) // The following commands are needed to redirect the standard output. However, Id like to have it closed right after the batch file finishes its job. Bat file : " + LatestFileName) ĮxceptionHandler.writeToLogFile("File not found") ĮxceptionHandler.writeToLogFile( + "Target : " + ex.TargetSite.ToString() + + "Message : " + ex.Message.ToString() + + "Stack : " + ex.StackTrace.ToString()) // Incidentally, /c tells cmd that we want it to execute the command that follows, and then exit. System.IO.StreamWriter srinput = process.StandardInput System.IO.StreamReader sroutput = process.StandardOutput ![]() System.IO.StreamReader stream = System.IO.File.OpenText(BatchPath + LatestFileName) If (System.IO.File.Exists(BatchPath + LatestFileName)) String LatestFileName = GetLastWrittenBatchFile() How can i determine Exit code ? public void Execute() And the c# code dosent give me exception or any notification.įor which i want to get the Exitcode from CMD to determine if the commands executed properly. The problem is sometimes the application dosent starts up after executing the batch file. For example, this fails: cmd /c 'exit 1' echo Hey Even better, this fails: cmd /c 'exit 1' & goto :eof. When you comment that cmd /c 'exit 1' works, it's because that also happens to be the last line of the script. I am using following code to write the PATH, EXECUTABLE NAME and ARGUMENTS to a batch file and execute it through CMD using c#. The exit code of the last line of your script is proxied to the exit code of the script itself.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |