簡體   English   中英

pexpect輸出未顯示

[英]pexpect output not showing

我們簡單的pexpect腳本具有以下功能:

import pexpect
import sys

test = pexpect.spawn('ftp www.today.com')
test.logfile = sys.stdout
test.expect('Name.*')

但是,在外殼程序上調用了腳本,沒有顯示任何輸出。 相反,它似乎掛起了,但我們可以看到生成了ftp ...進程。

如何在調用腳本的shell上顯示輸出?

謝謝

該行應:

test = pexpect.spawn('ftp www.today.com')

不是:

test = pexpect.spawn('ftp ftp.today.com')

因為通常如果您要ftp ,您必須使用ftp.something.com

test.logfile將僅包含命令的輸出,命令行本身未記錄在logfile屬性中。

因此,只要生成命令並且沒有輸出,調用腳本時外殼程序中就不會顯示任何內容。 例如,當達到ftp連接timout時將顯示。

您可能需要使用logfile_read 這是代碼:

import pexpect
import sys
test = pexpect.spawn('ftp www.today.com')
test.logfile_read = sys.stdout
test.expect('Name.*')

暫無
暫無

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

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