SharpSSH - SSHExec,运行命令,等待 5 秒获取数据!

发布于 2024-09-28 12:35:54 字数 665 浏览 2 评论 0原文

我有这段代码:

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 秒的数据,然后将其返回给我...... 有人知道我该怎么做吗?

我对此很陌生!我感谢所有帮助!谢谢你!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

海螺姑娘 2024-10-05 12:35:54

您可能想尝试以下重载:

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 执行其名称所暗示的操作,则它应该将命令的标准输出
stdOut 中的标准错误和 stdError 中的标准错误。

有关标准流的更多信息,请查看:http://en.wikipedia.org/wiki/Standard_streams< /a>

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文