【问题标题】:SSH.NET Expect() Unexpected PromptsSSH.NET Expect() 意外提示
【发布时间】:2020-09-06 16:01:10
【问题描述】:

我已经用我自己的命令翻译和 Ansible 扩展编写了我自己的 Linux 界面。我正在使用 Visual Studio 2019,连接到 CentOS,运行最新的 Ansible,同时使用 SSH.NET 进行连接。

因为这是 1000 行代码,这是一个非常高级的 sudo 代码,我正在这样做:

const string Command_Prompt = @"[\?$#]|\[.*@(.*?)\][$%#]";
var promptRegex = new Regex(Command_Prompt);
while(_lastCommand != "exit") {
    _lastCommand = Console.ReadLine();

    _shellStream.WriteLine(_lastCommand);
    var output = _shellStream.Expect(promptRegex);
    Log.Verbose(output);
}

这回升

[root@localhost ~]#
[root@localhost ~]$
#
$
What is your first name?

我的 Ansible ymls 有提示符,如果提示符有问号,这将非常有效。如果我期待某些特定的东西,它可以正常工作,因为我可以期待任何我喜欢的东西。但是,有时,我运行一个 linux 命令并且该命令有一个意想不到的提示,这是在等待预期的信息回来。有没有办法做 MRemote、Putty 或 VSCode 终端在未知提示下所做的事情?如果我不知道他们的提示会是什么样子,我真的不能让其他人使用我的产品。 MRemote、Putty 和 VSCode 终端具体做了哪些 SSH.NET 显然没有做的事情,或者我没有正确使用 SSH.NET?

【问题讨论】:

    标签: c# putty ssh.net


    【解决方案1】:

    我结束了,只是从基础开始。

    .*\?:|[$#]|\[.*@(.*?)\][$%#]
    

    拿起下面的

    [root@localhost ~]#
    [root@localhost ~]$
    #
    $
    What is your first name?:
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-10-14
      • 2010-12-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多