C# 如何获取netsh的错误代码?
我捕获如下过程的输出和退出代码:C# 如何获取netsh的错误代码?,c#,cmd,C#,Cmd,我捕获如下过程的输出和退出代码: Process proc = new Process { StartInfo = { RedirectStandardOutput = true, UseShellExecute = false, FileName = Environment.SystemDirectory + "\\netsh.exe", Arguments = "http delete urlacl url=ht
Process proc = new Process
{
StartInfo =
{
RedirectStandardOutput = true,
UseShellExecute = false,
FileName = Environment.SystemDirectory + "\\netsh.exe",
Arguments = "http delete urlacl url=http://+:8080/my/Url/Suffix"
}
};
proc.Start();
proc.WaitForExit();
int exitCode = proc.ExitCode;
string output = proc.StandardOutput.ReadToEnd();
当我检查退出代码时,它是
一,
当我检查流程的输出时,它是
URL保留删除失败,错误:2系统找不到指定的文件 输出正是我所期望的。我正在尝试删除一个不存在的预订。我需要的是隐藏在输出中的错误代码。我是否需要编写自己的自定义解析器来考虑netsh可能向我抛出的所有奇怪消息
有没有一种简单的方法来获取错误代码?看起来您需要使用正则表达式。@YuvalItzchakov在找到更好的方法之前,我就是这么做的。我担心我的正则表达式会很差,除非我知道
netsh delete-urlacl
可能输出的所有内容。