popen and two-way communication

S

Stephen Boulet

I'd like to use popen for a little script to call gnu privacy guard and
display decrypted text to a window.

Working from the dos prompt I can type in:

"gpg -d <filename>"

But then gpg then comes back at me with something like:

"""
You need a passphrase to unlock the secret key for
user: "xxxx <[email protected]>"
1024-bit ELG-E key, ID xxxxxx, created 2004-04-27 (main key ID xxxxxx)

Enter passphrase:
"""

After entering the passphrase the decrypted text gets dumped to the console.

How do I do this with popen?

Stephen

(Too bad the pexpect module doesn't work under windows.)
 
J

Jeff Shannon

cmkl said:
You may be interested in the new subprocess module:

1) PEP:
http://www.python.org/dev/doc/devel/whatsnew/node8.html

2) source code:
http://www.lysator.liu.se/~astrand/popen5/

3) Windows builds (pre Python-2.4):
http://effbot.org/downloads/#subprocess

This looks nice, but I suspect that it won't help the O.P.

Admittedly, I haven't tested subprocess. But interacting with SSH or
gpg or most other password-requesting programs doesn't work properly
through pipes. These programs read directly from the controlling TTY,
rather than from stdin. Pipes don't affect the controlling TTY, meaning
that you'll *still* be prompted for the password.

In short, some version of (or replacement for) Expect is probably still
needed. It is indeed too bad that pexpect won't work on Windows, or
more accurately that the pty which pexpect relies on doesn't work on
Windows... (Fortunately for me, I need to run ssh on Linux, so pexpect
should serve my purposes just fine.)

Jeff Shannon
Technician/Programmer
Credit International
 

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,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top