SharpSSH - SSHExec, run command, and wait 5 seconds for data!

你说的曾经没有我的故事 提交于 2019-12-13 02:48:56

问题


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... logo 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!


回答1:


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



来源:https://stackoverflow.com/questions/4008857/sharpssh-sshexec-run-command-and-wait-5-seconds-for-data

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!