How do I write to file descriptor 3 of a subprocess.Popen object?
I'm trying to accomplish the redirection in the following shell command with Python (without using named pipes):
$ gpg --passphrase-fd 3 -c 3<passphrase.txt < filename.txt > filename.gpg
The subprocess
proc
inherits file descriptors opened in the parent process. So you can useos.open
to open passphrase.txt and obtain its associated file descriptor. You can then construct a command which uses that file descriptor:To read from a pipe instead of a file, you could use
os.pipe
: