Redirecting stdout and stdin

  • Thread starter Matthew Thorley
  • Start date
M

Matthew Thorley

I am working on a script that calls a program ssh in this case. The
script needs to be non-interactive so I need python to comunicate with
ssh. I am having difficult time opening a pipe to the program and
reading and writing output to it. I tried using popen something like:

ssh = popen('ssh user@host')
if ssh[1].readline = 'something':
ssh[0].write('password')

Etc...


But everytime I run the thing stdout still shows up on the command line
and I get propmted to enter the password interactively.

Any thoughts ?

thanks much
-matthew
 
D

Donn Cave

I am working on a script that calls a program ssh in this case. The
script needs to be non-interactive so I need python to comunicate with
ssh. I am having difficult time opening a pipe to the program and
reading and writing output to it. I tried using popen something like:

ssh = popen('ssh user@host')
if ssh[1].readline = 'something':
ssh[0].write('password')

Etc...


But everytime I run the thing stdout still shows up on the command line
and I get propmted to enter the password interactively.

As suggested in another followup, you may need some type of
"expect" interface to deal with ssh's password prompt, because
ssh needs a tty device there. It turns off tty echo, and may
not be willing to proceed if the (pipe) device can't handle that
ioctl. It also needs a distinct source for the password input,
because it's supposed to read up stdin input and copy it to the
remote sshd, so it will open /dev/tty for the password.

If this sounds like a lot of trouble, it's really worse than it
sounds. Ssh can authenticate other ways besides passwords, and
that's really worth considering. In that case you can use plain
popen (instead of popen2 which you evidently were using above),
and stdout will not show up on the terminal (as it wasn't in
your experiment above - that was stderr.)

Donn Cave, (e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top