Simulate `bash` behaviour using Python and named pipes.

Luca Cerone luca.cerone at gmail.com
Mon Aug 5 12:54:24 EDT 2013


Thanks this works (if you add shell=True in Popen).
If I don't want to use shell = True, how can I redirect the stdout to named_pipe? Popen accepts an open file handle for stdout, which I can't open for writing because that blocks the process...

> 
> 
> os.mkfifo("named_pipe", 0777)
> 
> ls_process = subprocess.Popen("ls -lah > named_pipe")
> 
> pipe = open("named_pipe", "r")
> 
> # Read the output of the subprocess from the pipe.
> 
> 
> 
> When the subprocess terminates (look at the docs for Popen objects),
> 
> close and delete the fifo.




More information about the Python-list mailing list