簡體   English   中英

pxssh-使用某些長度的命令輸出未正確返回

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

當使用來自pexpect的pxssh(Python 3-v4.6.0,Python 2-v4.2.1)執行命令時,不返回命令的輸出,僅返回命令本身以及控制字符(下面的示例)。 僅在使用具有特定長度的命令時才會發生這種情況,例如,當將窗口大小設置為200時,對於窗口大小為300的命令,長度為189個字符的命令將觸發此行為,對於246個字符的命令等。

帶有相應輸出的示例代碼:

設定:

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)

正確的預期輸出:

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'

錯誤的輸出:

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

正確的預期輸出:

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'

有誰知道這可能是什么原因?

萬一將來有人遇到這個問題。 當一個命令的長度=窗口大小-提示長度時,就會發生此問題,這會導致一個附加提示被錯誤地插入到傳入數據中,進而導致輸出被錯誤地返回。

有關更多信息,請參見: https : //github.com/pexpect/pexpect/issues/552

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM