简体   繁体   中英

pexpect output not showing

Our simple pexpect script has this:

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.

How to have the output shown on the shell the script is invoked ?

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 .

test.logfile will only contain the output of the command, the command line itself is not logged in the logfile attribute.

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.

You might need to use 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.*')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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