本文介绍了的ExitCode始终为0执行.bat文件时,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我通常不是一个C#人,所以我希望这不是一个愚蠢的问题... 我有一个 .bat 文件(这当然是一个简化的例子): file nn.bat > exit / B 3 $ b b 当我从命令运行它时,看到%ERRORLEVEL%是3(太棒了!) 我有这个c#程式: C#程式 code> class Program { static void Main(string [] args) { Process p = new Process(); p.StartInfo.FileName = @nn.bat; p.Start(); p.WaitForExit(); int rc = p.ExitCode; Console.WriteLine(rc); } } 我希望 rc 我的错误在哪里?最后,我找到了一个解决方法: 在我的批处理文件中,而不是使用 exit / B 3 我使用 exit 3 。 (和解释)来自此答案 我仍然可以不能解释它如何为其他人使用 / B 选项 - 我的猜测是它必须做一些与他们的操作系统版本。 I'm usually not a C# person, so I hope it's not a stupid question...I have a .bat file that looks like this (this is of course a simplified example):file nn.batexit /B 3When I run it from command I see that %ERRORLEVEL% is 3 (great!!)I have this c# program:C# Programclass Program{ static void Main(string[] args) { Process p = new Process(); p.StartInfo.FileName = @"nn.bat"; p.Start(); p.WaitForExit(); int rc = p.ExitCode; Console.WriteLine(rc); }}I expect rc to be 3, but it's always 0 no matter what I try ...Where is my mistake ? 解决方案 Finally, I've found a workaround: In my batch file, instead of using exit /B 3 I used exit 3.The idea (and explanation) came from this answerI still can't explain how it worked for others with the /B option - my guess is that it has to do something with their operating system version. 这篇关于的ExitCode始终为0执行.bat文件时,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-31 23:56