检测 VT100 SSH 会话流中的控制台提示符

发布于 2024-09-09 00:16:44 字数 490 浏览 1 评论 0原文

我正在开发一个包装库(在 C# 中,但对于这里的问题并不重要)来打开 SSH 连接,然后允许向服务器发送命令并接收响应。然而,最重要的是,我想让命令调用缓冲响应流,然后在 shell 返回到控制台提示符后将其全部作为一个字符串返回给用户。这样,我可以只触发一个命令,而不必在作业期间每次服务器写回控制台时处理所有响应事件。

所以,我的主要问题是,在 VT100 会话中,是否有任何万无一失的方法来确定服务器已返回输入提示?到目前为止我发现的唯一一件事是,对于我尝试过的两个 ssh 服务器(cygwin 和 Fedora),它总是输出的最后一个字符序列是 '[esc][0m' [esc],是 ASCII代码 27 我想认为这是标准的东西,但是当我查找该序列是什么时,我发现了这一点:

modesoff SGR0,关闭字符 属性

我希望有更具体的东西,比如“等待输入”:P

如果这适用于所有/大多数系统,有什么想法吗?或者是否有更好的方法?

I'm working on a wrapper library (in C#, but not really important to the issue here) to open an SSH connection and then allow for sending commands to the server and receiving the response. The main thing, however, is that I want to have the command call buffer the response stream and then return it all as one string to the user once the shell has returned to the console prompt. That way, I can just fire off a command and not have to deal with all the response events every time the server writes back to the console during the job.

So, my main question is, in a VT100 session, is there any fool-proof way of determining that the server has returned to the input prompt? The only thing I've found so far is that, with the two ssh servers I've tried (cygwin and Fedora), the last character sequence it always seems to output is '[esc][0m' [esc], being ASCII code 27 I would like to think that this is something standard, but when I looked up what that sequence is I found this:

modesoff SGR0, Turn off character
attributes

I was kind of hoping for something more concrete, like "Waiting for input" :P

Any ideas if this should work for all/most systems? Or if there is a better way?

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

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

发布评论

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

评论(1

故事未完 2024-09-16 00:16:44

字符属性(如粗体、闪烁、暗淡、下划线、突出显示等)都被分配了数字代码,并且可以以转义序列链接在一​​起以更改监视器上文本的显示。

ESC [ 0 m 序列关闭所有设置,将文本返回到“正常”,这是常规亮度,没有其他视觉属性。

VT100 仅显示串行端口上传入的字符。因此,提示的内容很大程度上取决于您将终端连接到的内容,并且很可能解释了为什么您没有得到答案。

通常,具有提示的系统具有用户可自定义的提示,并且您可能可以烘焙隐藏的字符序列(如果不是控制字符),然后您可以在会话中检测到这些字符。

另一种方法(虽然不太可靠)是等待主机一段时间不活动,这通常意味着它正在等待输入(但并非总是如此)。

Character attributes, like bold, blinking, dim, underline, highlighted, etc. are all assigned numerical codes and can be chained together in an escape sequence to alter the display of text on the monitor.

The ESC [ 0 m sequence turns off all the settings, returning text to "normal," which is regular brightness and no other visual attributes.

The VT100 is merely displaying characters coming in on its serial port. So what constitutes a prompt is highly dependent on what you connect the terminal to, and most likely explains why you haven't gotten an answer.

Often systems that have prompts have user-customizable prompts, and it's likely that you can bake in a hidden sequence of characters, if not control characters, that you could then detect in your session.

Another way, though not as reliable, is to wait for a duration of inactivity from the host, which usually implies it's waiting for input (but not always).

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