简体   繁体   English

pxssh-使用某些长度的命令输出未正确返回

[英]pxssh - Output not returning correctly with certain length command

When using pxssh from pexpect (Python 3-v4.6.0, Python 2-v4.2.1) to execute a command, the output of the command is not returned, only the command itself along with a control character (example below). 当使用来自pexpect的pxssh(Python 3-v4.6.0,Python 2-v4.2.1)执行命令时,不返回命令的输出,仅返回命令本身以及控制字符(下面的示例)。 This only occurs when using a command with a particular length, for example when setting the window size to 200, a command of length 189 character will trigger this behaviour, for a window size of 300, a 246 character command etc. 仅在使用具有特定长度的命令时才会发生这种情况,例如,当将窗口大小设置为200时,对于窗口大小为300的命令,长度为189个字符的命令将触发此行为,对于246个字符的命令等。

Example code with respective outputs: 带有相应输出的示例代码:

Setup: 设定:

from pexpect import pxssh
conn = pxssh.pxssh()
conn.login(host, user, password)
conn.setwinsize(500, 200)
conn.setecho(False)
conn.sendline('')
conn.prompt(1)
conn.prompt(1)

Correct Expected Output: 正确的预期输出:

conn.sendline('l'*188)
conn.prompt(1)
conn.before
b'llll**snip**lllll\x1b[Kl\r\n-sh: lllll*snip*lllll: command not found\r\n'

Incorrect Output: 错误的输出:

conn.sendline('l'*189)
conn.prompt(1)
conn.before
b'lllll**snip**lllll\r\x1b[A'

Correct Expected Output: 正确的预期输出:

conn.sendline('l'*190)
conn.prompt(1)
conn.before
b'lllll**snip**llllll\x1b[Kl\r\n-sh: lllll**snip**llllll: command not found\r\n'

Does anyone know what might be causing this? 有谁知道这可能是什么原因?

In case anyone comes across this problem in the future. 万一将来有人遇到这个问题。 This issue occurs when a command of length = window size - length of prompt, which causes an additional prompt to incorrectly be inserted into the incoming data in turn causing the output to be incorrectly returned. 当一个命令的长度=窗口大小-提示长度时,就会发生此问题,这会导致一个附加提示被错误地插入到传入数据中,进而导致输出被错误地返回。

For more information see: https://github.com/pexpect/pexpect/issues/552 有关更多信息,请参见: https : //github.com/pexpect/pexpect/issues/552

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM