This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ropoctorix
Recipients ropoctorix
Date 2013-07-24.14:00:00
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1374674400.76.0.00470955001934.issue18544@psf.upfronthosting.co.za>
In-reply-to
Content
Popen() ought to support redirection to/from more file descriptors than 0, 1, and 2 when spawning processes. A clear use case is here: http://stackoverflow.com/questions/6050187/write-to-file-descriptor-3-of-a-python-subprocess-popen-object

Instead of messing around with os.open() and os.close() calls, my proposed API for Popen would be to accept keyword arguments fdN that would take the same type of values as the stdin, stdout, stderr arguments. Conflicting fd0 and stdin arguments would throw an exception.

So the smelly code in the above SO question would be changed to:


cmd='gpg --passphrase-fd {fd} -c'.format(fd=fd)
with open('passphrase.txt','r') as fd3_fh:
    with open('filename.txt','r') as stdin_fh:
        with open('filename.gpg','w') as stdout_fh:        
            proc=subprocess.Popen(shlex.split(cmd),
                                  stdin=stdin_fh,
                                  stdout=stdout_fh,
                                  fd3=fd3_fh)
            proc.communicate()
History
Date User Action Args
2013-07-24 14:00:00ropoctorixsetrecipients: + ropoctorix
2013-07-24 14:00:00ropoctorixsetmessageid: <1374674400.76.0.00470955001934.issue18544@psf.upfronthosting.co.za>
2013-07-24 14:00:00ropoctorixlinkissue18544 messages
2013-07-24 14:00:00ropoctorixcreate