2010-10-24 50 views
0

我有這樣的代碼:SharpSSH - SSHExec,運行命令,並等待5秒的數據!

using System; 
using System.Text; 
using Tamir.SharpSsh; 
using System.IO; 

namespace ConsoleApplication1 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 
      SshExec exec = new SshExec("192.168.0.1", "admin", "haha"); 
      exec.Connect(); 
      string output = exec.RunCommand("interface wireless scan wlan1 duration=5"); 
      Console.WriteLine(output); 
      exec.Close(); 
     } 
    } 
} 

該命令將執行!我可以看到,但!它立即打印數據。或者實際上,它不會打印命令中的數據。它打印像mikrotik os的...徽標。我實際上需要命令中的數據,而我需要SharpSSH等待至少5秒鐘的數據,然後將其還給我... 有人知道我該如何做到這一點?

我對此很新!我感謝所有幫助!謝謝!

+0

我不熟悉SharpSsh,但它似乎在.RunCommand不會等那麼久...改變你的代碼將不會幫助,你需要找出是否有不同的運行命令。 – TimothyP 2010-10-25 05:57:51

回答

1

你可能想嘗試以下過載:

SshExec exec = new SshExec("192.168.0.1", "admin", "haha"); 
exec.Connect(); 
string stdOut = null; 
string stdError = null; 
exec.RunCommand("interface wireless scan wlan1 duration=5", ref stdOut, ref stdError); 

Console.WriteLine(stdOut); 
exec.Close(); 

如果他們的API做什麼顧名思義,它應該把你在標準輸出命令 的標準輸出和stdError標準錯誤。

有關標準流的更多信息,檢查了這一點:http://en.wikipedia.org/wiki/Standard_streams