SharpSSH - SSHExec,运行命令,并等待5秒的数据! [英] SharpSSH - SSHExec, run command, and wait 5 seconds for data!

查看:1718
本文介绍了SharpSSH - SSHExec,运行命令,并等待5秒的数据!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个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();
        }
    }
}

该命令将执行!我可以看到,但!它立即打印数据。或实际上,它一点儿也不从命令打印数据。它打印像...标识为的MikroTik操作系统。我真的需要从命令中的数据,我需要SharpSSH等待至少5秒钟的数据,然后还给我... 有人知道我怎么能做到这一点?

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?

我是pretty的新本!我AP preciate所有帮助!谢谢!

I'm pretty new to this! I appreciate all help! Thank you!

推荐答案

您可以试试以下过载:

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的标准误差。

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.

有关标准流的更多信息,检查了这一点: http://en.wikipedia.org/wiki / Standard_streams

For more information about standard streams, check this out: http://en.wikipedia.org/wiki/Standard_streams

这篇关于SharpSSH - SSHExec,运行命令,并等待5秒的数据!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆