我已经用我自己翻译的命令和Ansible扩展将我自己的接口写进了Linux。我正在使用Visual Studio2019,连接到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有提示符,如果提示符有问号,它就能很好地工作。如果我期望的是特定的东西,它可以很好地工作,因为我可以传递给expect任何我喜欢的东西。但是,有时候,我运行一个linux命令,该命令出现意外的提示符,这是在等待预期的信息返回。有没有办法像MRemote、Putty或VSCode终端那样处理未知提示?如果我不知道他们的提示会是什么样子,我就不能允许其他人使用我的产品。MRemote、Putty和VSCode终端具体做了什么是SSH.NET显然不做的,或者是我没有正确使用SSH.NET?
发布于 2020-09-14 07:26:25
最后,我选择了最基本的。
.*\?:|[$#]|\[.*@(.*?)\][$%#]拾取以下内容
[root@localhost ~]#
[root@localhost ~]$
#
$
What is your first name?:https://stackoverflow.com/questions/63766143
复制相似问题