Linux 当我在脚本中使用它时,无法使用 echo "^]" 关闭 scpi(telnet) 会话

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11681683/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 13:56:21  来源:igfitidea点击:

Can't close a scpi(telnet) session with echo "^]" when I use it in a script

linuxtelnet

提问by Bernie

The use of echo-e "\ 029"does not work either. But if use strg+ alt gr+ ]directly in a terminal session -> it works.

的使用echo-e "\ 029"也不起作用。但是,如果使用strg+ alt gr+]直接在终端会话- >它的工作原理。

I have to ask my question more concretely:
I connect an RF generator (AGILENT) via Telnet/SCPI.
If I do this manual on terminal and press at the end of the session CTRL+ ALT GR+]for '^]' then close the scpi session properly and I can type quitto close the telnet session properly.
There is no error message on the display of the RF generator. So it should be.

我必须更具体地提出我的问题:
我通过 Telnet/SCPI 连接了一个 RF 发生器 (AGILENT)。
如果我在终端上执行本手册并在会话结束时按CTRL+ ALT GR+]为 '^]' 然后正确关闭 scpi 会话,我可以键入quit以正确关闭 telnet 会话。
射频发生器的显示屏上没有错误消息。所以应该是。

If I do this via script the SCPI session seems not to recognize the break signal condition '^]' and will be forced to close after the end of the script (telnet and scpi). -> Message: "Disconnected by foreign host". Unfortunately, I get error messages on the display of the RF generator -> "invalid header", etc.

如果我通过脚本执行此操作,SCPI 会话似乎无法识别中断信号条件“^]”,并且将在脚本(telnet 和 scpi)结束后被迫关闭。-> 消息:“被外部主机断开连接”。不幸的是,我在 RF 发生器的显示屏上收到错误消息 ->“无效标头”等。

After successful connection appears: Connected to 192,168.10.66 Escape Character is ‘^]' -> This is the point at issue. Manual entry in the terminal works correctly, script does not work.

连接成功后出现:Connected to 192,168.10.66 Escape Character is '^]' -> 这就是问题所在。终端中的手动输入工作正常,脚本不起作用。

My script looks something like this:

我的脚本看起来像这样:

function  getIDNMessage()  
{
    (      
        echo open    
        sleep 1  
        echo "*IDN?"  
        sleep 1  
        echo –e "9"         # or echo “^]” does not work well  
        sleep 1  
        echo "quit\r"  
        sleep 1  
    ) | telnet > scpi_telnet.log 2>&1
}

getIDNMessage 192.168.10.66 7777    

回答by Igor Chubin

It must be so. Because ^]printed in the terminal on the server means for the client side nothing. The client must catch this symbol before it will be transmitted to server and of course you can't just write it to terminal in te program running on the server.

一定是这样。因为^]在服务器的终端上打印对于客户端来说意味着什么。客户端必须在它被传输到服务器之前捕获这个符号,当然你不能在服务器上运行的程序中将它写入终端。

So you need to interrupt session in other way. There are many methods.

所以你需要以其他方式中断会话。有很多方法。

  1. If you are inside the running program, you can simple terminate it (exitin shell or sys.exit()in python or exit()in many other languages).
  2. If you can't control program flow you can close terminal by killing the process that is owner of the terminal. You need to find the process and then use kill ...(PID of the process instead of ...).
  3. If you want to close the client from client side, you need to do the same (kill ...) but on the client side.
  1. 如果您在正在运行的程序中,您可以简单地终止它(exit在 shell 或sys.exit()python 或exit()许多其他语言中)。
  2. 如果您无法控制程序流程,您可以通过杀死终端所有者的进程来关闭终端。您需要找到进程,然后使用kill ...(进程的 PID 而不是...)。
  3. 如果要从客户端关闭客户端,则需要在客户端执行相同的操作 ( kill ...)。

回答by KaHymandfw

On Linux it's actually:

在 Linux 上它实际上是:

CTRL+ ]then ENTER

CTRL+]然后ENTER

Finally type in the quitcommand.

最后输入quit命令。

^]

telnet> quit
Connection closed.
[fred@localhost ~]$

回答by Kindi BALDE

To quit telnet on redhat:
type "CTRL+5"and then type "quit"

在 redhat 上退出 telnet:
输入"CTRL+5"然后输入"quit"

回答by Walk

The ^]means ctrl + rightbracket. As strange as that is, it works. You'll be taken to the telnet prompt, where you can type quit.

^]装置ctrl + right支架。尽管很奇怪,但它确实有效。您将进入 telnet 提示符,您可以在其中键入 quit。

On international keyboards the ]character is often not a single key, and needs to be replaced with some other key. The correct key is typically the key to the right of P or the next key after that.

在国际键盘上,]字符通常不是单个键,需要用其他键替换。正确的键通常是 P 右侧的键或之后的下一个键。

Here's a list based on comments below:

这是基于以下评论的列表:

Finnish, Swedish, Norwegian, Danish: ctrl + ?
French: ctrl + 6
German: ctrl + ü
Swiss: ctrl + ¨
Hungarian: ctrl + 5
Portuguese: ctrl + ′
Dutch, Belgian: ctrl + $
Canadian French: ctrl + ?

回答by Kristian

On my danish keyboard it was not Ctrl+ ?- but instead the key to the right side of ?(which has a hat, a tilde and a umlaut)

在我的丹麦语键盘上,它不是Ctrl+ ?- 而是右侧的键?(有帽子、波浪号和元音变音)

回答by Pratiyush Kumar Singh

To Close Session Use below command

关闭会话使用以下命令

  1. Ctrl + ]
  2. telnet> quit
  1. Ctrl + ]
  2. telnet> 退出

it works perfect in REHL and CentOS.

它在 REHL 和 CentOS 中完美运行。

回答by Sadee

Ctrl + ]This will show as ^] and then

Ctrl + ]这将显示为 ^] 然后

telnet> qq is for quit

telnet> qq 是退出

回答by 0x01h

On MacOS with Turkish keyboard try:
Ctrl+ Option+ ü

Then,
> quit

在带有土耳其语键盘的 MacOS 上尝试:
Ctrl+ Option+ü

然后,
> quit