chz
chz

Reputation: 387

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

Upvotes: 0

Views: 1464

Answers (3)

SKT
SKT

Reputation: 174

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.*')

Upvotes: 0

rparent
rparent

Reputation: 628

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.

Upvotes: 0

Tony The Lion
Tony The Lion

Reputation: 63190

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.

Upvotes: 1

Related Questions