pexpect输出没有显示

时间:2013-03-08 06:16:13

标签: python pexpect

我们简单的pexpect脚本有:

import pexpect
import sys

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

但是,在shell上调用了脚本,没有显示输出。 相反,它似乎挂了,但我们可以看到进程ftp ...产生。

如何在shell上显示输出脚本?

感谢

3 个答案:

答案 0 :(得分:1)

这一行:

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

不是:

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

因为通常如果你想要ftp,你必须使用ftp.something.com

答案 1 :(得分:0)

test.logfile只包含命令的输出,命令行本身未记录在logfile属性中。

因此,只要生成命令并且没有输出,调用脚本时shell中不会显示任何内容。 例如,当达到ftp连接时间时,将显示。

答案 2 :(得分:0)

您可能需要使用logfile_read。这是代码:

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