How to send a var to stdin of an external software

Floris Bruynooghe floris.bruynooghe at gmail.com
Fri Mar 14 10:47:15 EDT 2008


On Mar 14, 11:37 am, Benjamin Watine <wat... at cines.fr> wrote:
> Bryan Olson a écrit :
>
> > I wrote:
> >> [...] Pipe loops are tricky business.
>
> >> Popular solutions are to make either the input or output stream
> >> a disk file, or to create another thread (or process) to be an
> >> active reader or writer.
>
> > Or asynchronous I/O. On Unix-like systems, you can select() on
> > the underlying file descriptors. (MS-Windows async mechanisms are
> > not as well exposed by the Python standard library.)
>
> Hi Bryan
>
> Thank you so much for your advice. You're right, I just made a test with
> a 10 MB input stream, and it hangs exactly like you said (on
> cat.stdin.write(myStdin))...
>
> I don't want to use disk files. In reality, this script was previously
> done in bash using disk files, but I had problems with that solution
> (the files wasn't always cleared, and sometimes, I've found a part of
> previous input at the end of the next input.)
>
> That's why I want to use python, just to not use disk files.
>
> Could you give me more information / examples about the two solutions
> you've proposed (thread or asynchronous I/O) ?

The source code of the subprocess module shows how to do it with
select IIRC.  Look at the implementation of the communicate() method.

Regards
Floris



More information about the Python-list mailing list