[Python-Dev] Implementing File Modes
Eric Pruitt
eric.pruitt at gmail.com
Thu Jul 30 05:02:22 CEST 2009
Well, with a few changes to your code, that would indeed work (you are using
stdin as your pipe. Correct me if I'm wrong but if you intend to read from
it, you need to change it to "stdout = subprocess.PIPE" and the other lines
as well to reflect this change). My Google Summer of Code modifications to
subprocess.Popen provide non-blocking, asynchronous I/O support and my file
wrapper is built upon that augmented functionality. If I remember correctly,
when I was working on the program where I first thought a file wrapper for
subprocess.Popen would be rather handy, I also ran into blocking I/O as
well.
On Wed, Jul 29, 2009 at 20:20, Devin Cook <devin.c.cook at gmail.com> wrote:
> Hmm... can't you do this?
>
> if encryptionEnabled:
> p = subprocess.Popen(["gpg", "--decrypt", "supersecret.html.gpg"],
> stdin = subprocess.PIPE)
> fileobj = p.stdin
> else:
> fileobj = open("notsosecret.html")
>
> I think that works. Is there something this way won't work for? You
> can also do the same thing to get stdout and stderr file objects. I
> guess a wrapper would simplify this process.
>
> -Devin
>
> On Wed, Jul 29, 2009 at 7:41 PM, Eric Pruitt<eric.pruitt at gmail.com> wrote:
> > My motivation came from an instance when I was using subprocess.Popen for
> a
> > Linux / Windows cross platform program. In part of the program, I was
> > writing and reading to a cron like object. On Windows, it was a text file
> > and on Linux it would be the crontab executable. Had I been able to
> > substitute the "open()" function with my wrapper, it would have been the
> > only change I had to make for cross platform compatibility; instead of
> > having to change numerous lines because Linux would need Popen and
> Windows
> > would need a regular file open(), I could simply make it so that if the
> > platform was Linux, my wrapper is used in place of that. Just another
> > example would be having an external program decrypt a file that can be in
> > plain text or encrypted that might go something like this:
> >
> > if encryptionEnabled:
> > fileobj = subprocess.ProcessIOWrapper("gpg --decrypt
> > supersecret.html.gpg")
> > else:
> > fileobj = open("notsosecret.html")
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20090729/06079ff7/attachment.htm>
More information about the Python-Dev
mailing list