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.<br>
<br><div class="gmail_quote">On Wed, Jul 29, 2009 at 20:20, Devin Cook <span dir="ltr"><<a href="mailto:devin.c.cook@gmail.com">devin.c.cook@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hmm... can't you do this?<br>
<br>
if encryptionEnabled:<br>
p = subprocess.Popen(["gpg", "--decrypt", "supersecret.html.gpg"],<br>
stdin = subprocess.PIPE)<br>
fileobj = p.stdin<br>
<div class="im">else:<br>
fileobj = open("notsosecret.html")<br>
<br>
</div>I think that works. Is there something this way won't work for? You<br>
can also do the same thing to get stdout and stderr file objects. I<br>
guess a wrapper would simplify this process.<br>
<font color="#888888"><br>
-Devin<br>
</font><div><div></div><div class="h5"><br>
On Wed, Jul 29, 2009 at 7:41 PM, Eric Pruitt<<a href="mailto:eric.pruitt@gmail.com">eric.pruitt@gmail.com</a>> wrote:<br>
> My motivation came from an instance when I was using subprocess.Popen for a<br>
> Linux / Windows cross platform program. In part of the program, I was<br>
> writing and reading to a cron like object. On Windows, it was a text file<br>
> and on Linux it would be the crontab executable. Had I been able to<br>
> substitute the "open()" function with my wrapper, it would have been the<br>
> only change I had to make for cross platform compatibility; instead of<br>
> having to change numerous lines because Linux would need Popen and Windows<br>
> would need a regular file open(), I could simply make it so that if the<br>
> platform was Linux, my wrapper is used in place of that. Just another<br>
> example would be having an external program decrypt a file that can be in<br>
> plain text or encrypted that might go something like this:<br>
><br>
> if encryptionEnabled:<br>
> fileobj = subprocess.ProcessIOWrapper("gpg --decrypt<br>
> supersecret.html.gpg")<br>
> else:<br>
> fileobj = open("notsosecret.html")<br>
><br>
</div></div></blockquote></div><br>