C# 如何在C中运行tracetcp并获得输出结果?

C# 如何在C中运行tracetcp并获得输出结果?,c#,system.diagnostics,C#,System.diagnostics,下面是我的代码。 我的代码中是否有错误或缺失 using (Process p = new Process()) { string strCmdText = string.Empty; p.StartInfo.FileName = "CMD.exe"; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.UseShellExecute = false; p.StartInfo.Arguments =

下面是我的代码。 我的代码中是否有错误或缺失

using (Process p = new Process())
{
    string strCmdText = string.Empty;
    p.StartInfo.FileName = "CMD.exe";
    p.StartInfo.RedirectStandardOutput = true;
    p.StartInfo.UseShellExecute = false;
    p.StartInfo.Arguments = "tracetcp vrtpmkap2001:445";
    p.Start();
    string q = string.Empty;
    while (!p.HasExited)
    {
        q += p.StandardOutput.ReadToEnd();
    }
    string r = q.ToString();
}
我无法获取tracetcp的输出。

请使用以下代码:

string cmd = "/c tracetcp vrtpmkap2001:445" ; 
System.Diagnostics.Process proc = new System.Diagnostics.Process(); 
proc.StartInfo.FileName = "cmd.exe"
proc.StartInfo.Arguments = cmd; 
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardOutput = true; 
proc.Start();
string output = proc.StandardOutput.ReadToEnd();
谢谢大家

我已经解决了这个问题。 当c运行cmd.exe时,它使用SysWOW64 cmd.exe

我只是将tracetcp.exe添加到SysWOW64文件夹中