Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!feeder.erje.net!eu.feeder.erje.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Gregory Ewing Newsgroups: comp.lang.python Subject: Re: Simulate `bash` behaviour using Python and named pipes. Date: Sat, 10 Aug 2013 13:07:03 +1200 Lines: 22 Message-ID: References: <7f5c60c4-50c7-4a93-af22-5c8549f87461@googlegroups.com> <92074090-ae9e-4219-ae0f-21592e8f0133@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net vkxAS2rVKRC1zZlAbei9+A77UFEM2DpTVNEO7rzpMeppI7Fi7m Cancel-Lock: sha1:Pcw9dEn1HDeTP6/uV8xWlr70yCE= User-Agent: Mozilla Thunderbird 1.0.5 (Macintosh/20050711) X-Accept-Language: en-us, en In-Reply-To: <92074090-ae9e-4219-ae0f-21592e8f0133@googlegroups.com> Xref: csiph.com comp.lang.python:52287 Luca Cerone wrote: > Thanks! I managed to make it work using the threading library :) If at least one of the external programs can accept the source or destination as a filename argument instead of redirecting its stdin or stdout, you can also do something like this: import subprocess p2 = subprocess.Popen(["cat", "named_pipe"]) pipe = open("named_pipe", "w") p1 = subprocess.Popen(["ls", "-lah"], stdout = pipe) pipe.close() p1.wait() p2.wait() That works because opening the reading end of the pipe is done by the subprocess executing cat, leaving the main process free to open the other end. -- Greg