Kevin Erickson wrote:
> On Jun 30, 5:50 pm, Kevin Erickson <[EMAIL PROTECTED]> wrote:
> > #Begin Code
> >
> > import sys
> > import pexpect
> >
> > def GetServerData(self):
> > foo = pexpect.spawn('scp [EMAIL PROTECTED]:/home/config/
> > role{/file1,/files/file2,/files/file3} /tmp')
> > foo.expect('.*password:*')
> > foo.sendline('server_password')
> > foo.interact()
...
> I have found a work around for my problem. I replace the following line:
>
> foo.interact()
> with
> foo.expect(pexpect.EOF)
That is correct. But why did you try using interact() method in the
first place?
I just want to know to see if I could improve the documentation.
After you send the password the 'scp' command should finish quickly
and exit,
so there would be nothing for a human to interact with.
You could also try using the run() function which is a simplified
interface to pexpect.
Something like this might work:
pexpect.run ('scp [EMAIL PROTECTED]:/home/config/role{/file1,/files/
file2,/files/file3} /tmp',
events={'(?i)password': 'server_password'})
That's all there is to it. The run() function will run the given scp
command.
When it see 'password' in the output it will send the server_password.
Yours,
Noah
Yours,
Noah
--
http://mail.python.org/mailman/listinfo/python-list