SharpSSH - SSHExec, run command, and wait 5 seconds for data!
I have this code:
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();
}
}
}
The command will execute! I can see that, but! It immediately prints data. Or actually, it does'nt print the data from the command. It prints like the... lo开发者_Go百科go for the mikrotik os. I actually need the data from the command, and I need SharpSSH to wait at least 5 seconds for data, then give it back to me... Somebody knows how I can do this?
I'm pretty new to this! I appreciate all help! Thank you!
You may want to try the following overload:
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();
If their API does what the name implies, it should put the standard output of your command in stdOut and the standard error in stdError.
For more information about standard streams, check this out: http://en.wikipedia.org/wiki/Standard_streams
精彩评论