2014-11-06 38 views
0

以下是我的代碼。 我的代碼中是否有錯誤或遺漏?如何在C#中運行tracetcp並獲取輸出結果?

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的輸出。

回答

0

使用此代碼:

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(); 
0

謝謝大家。

我已經找出問題所在。 當c#運行一個cmd.exe它使用SysWOW64 cmd.exe

我只是在SysWOW64文件夾中添加tracetcp.exe。

相關問題