简体   繁体   English

pexpect输出未显示

[英]pexpect output not showing

Our simple pexpect script has this: 我们简单的pexpect脚本具有以下功能:

import pexpect
import sys

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

However, on the shell the script was invoked, there's no output shown. 但是,在外壳程序上调用了脚本,没有显示任何输出。 Instead it seems to hang but we could see the process ftp ... is spawned. 相反,它似乎挂起了,但我们可以看到生成了ftp ...进程。

How to have the output shown on the shell the script is invoked ? 如何在调用脚本的shell上显示输出?

thanks 谢谢

Should this line: 该行应:

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

not be: 不是:

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

because normally if you want ftp , you'll have to use ftp.something.com . 因为通常如果您要ftp ,您必须使用ftp.something.com

test.logfile will only contain the output of the command, the command line itself is not logged in the logfile attribute. test.logfile将仅包含命令的输出,命令行本身未记录在logfile属性中。

So as long as the command is spawned and that there is no output, nothing will be displayed in the shell when invoking your script. 因此,只要生成命令并且没有输出,调用脚本时外壳程序中就不会显示任何内容。 There will be a display when for example the ftp connection timout has been reached. 例如,当达到ftp连接timout时将显示。

You might need to use logfile_read . 您可能需要使用logfile_read Here is the code: 这是代码:

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