Redirecting stdout and stdin

Discussion in 'Python' started by Matthew Thorley, Mar 4, 2004.

  1. 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 [email protected]')
    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
     
    Matthew Thorley, Mar 4, 2004
    #1
    1. Advertisements

  2. look for pyexpect.
     
    Diez B. Roggisch, Mar 4, 2004
    #2
    1. Advertisements

  3. Matthew Thorley

    Donn Cave Guest

    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,
     
    Donn Cave, Mar 4, 2004
    #3
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.