在Java中发送TAB控制字符
我正在使用 Ganymede ssh 库 (http://www.ganymed.ethz.ch/ssh2/) 连接到 ssh 服务器(显然;))。
通常,在使用 bash 时,当用户按键盘上的 TAB 键时,会出现可能的命令完成列表。我想实现相同的行为,但手动发送制表符。不幸的是我不知道该怎么做。发送“\t”不起作用。
编辑:解决方案必须是一个通用的,它不仅可以在bash中工作,而且可以在其他程序中工作,例如octave(使用命令行的开源matlab实现,只是不能应用bash命令的示例) 。
I am using the Ganymede ssh library (http://www.ganymed.ethz.ch/ssh2/)
to connect to a ssh server (obviously ;)).
Normally, when using the bash, when a user presses the TAB key on the keyboard a list of possible command completions appears. I want to achieve the same behaviour, but send the tab character manually. Unfortunately I am not aware how to do this. Sending "\t" does not work.
Edit: The solution must be a generic which does not only work in bash, but also in other programs, like octave (open source matlab implementation with command line, just an example where bash commands cannot be applied).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
正如 Joachim Sauer 所说,这可能是因为您的会话没有附加终端,因此 Bash 等程序的行为就像它们被非交互式调用一样。
Ganymede ssh 库的文档暗示调用 session.requestPTY(...) 将要求 SSH 服务器将伪 TTY 附加到会话。这就像将“-t”标志传递给 ssh 命令。
代码示例:
As Joachim Sauer said, this is probably because your session does not have a terminal attached, so programs such as Bash will behave as though they have been called non-interactively.
The documentation for Ganymede ssh library implies that calling session.requestPTY(...) will ask the SSH server to attach a pseudo TTY to the session. It is like passing the "-t" flag to the ssh command.
Code sample:
您可以使用此命令:
它列出 shell 中所有可能的命令。您可以添加
过滤输出
You can use this command :
It list all possible commands in the shell. You may add
to filter the output
你说的不是依赖于命令shell吗?我认为 '\t' 不起作用,因为这是制表符,而不是制表符按键,它被 shell 解释为列出可能的命令完成的命令。
因为这是您要询问的库,所以在我看来您想要什么,您必须自己实现,因为我认为 shell 通常会处理这个问题。
Isn't what you're talking about dependent on the command shell? I don't think '\t' works because that's the tab character, not the tab keypress which gets interpreted by your shell as a command that lists the possible command completions.
As this is a library you're asking about, it seems to me what you want, you'd have to implement yourself as the shell normally handles that, I think.