Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #51976

Re: Simulate `bash` behaviour using Python and named pipes.

Date 2013-08-05 20:45 +0100
From MRAB <python@mrabarnett.plus.com>
Subject Re: Simulate `bash` behaviour using Python and named pipes.
References (2 earlier) <7f5c60c4-50c7-4a93-af22-5c8549f87461@googlegroups.com> <mailman.211.1375714293.1251.python-list@python.org> <fad1a298-993c-4935-9f32-7cf20ca63796@googlegroups.com> <mailman.214.1375718915.1251.python-list@python.org> <ec4048f5-fb66-4c4a-81c4-77435524e087@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.216.1375731902.1251.python-list@python.org> (permalink)

Show all headers | View raw


On 05/08/2013 17:54, Luca Cerone wrote:
> 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...
>
You're back to using separate threads for the reader and the writer.
The one that opens the pipe first will block until the other one opens
the other end.

>>
>>
>> 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.
>

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Simulate `bash` behaviour using Python and named pipes. Luca Cerone <luca.cerone@gmail.com> - 2013-08-05 06:09 -0700
  Re: Simulate `bash` behaviour using Python and named pipes. Paul Wiseman <poalman@gmail.com> - 2013-08-05 14:39 +0100
    Re: Simulate `bash` behaviour using Python and named pipes. Luca Cerone <luca.cerone@gmail.com> - 2013-08-05 06:51 -0700
  Re: Simulate `bash` behaviour using Python and named pipes. MRAB <python@mrabarnett.plus.com> - 2013-08-05 15:03 +0100
    Re: Simulate `bash` behaviour using Python and named pipes. Luca Cerone <luca.cerone@gmail.com> - 2013-08-05 07:11 -0700
      Re: Simulate `bash` behaviour using Python and named pipes. MRAB <python@mrabarnett.plus.com> - 2013-08-05 15:51 +0100
        Re: Simulate `bash` behaviour using Python and named pipes. Luca Cerone <luca.cerone@gmail.com> - 2013-08-05 08:27 -0700
          Re: Simulate `bash` behaviour using Python and named pipes. MRAB <python@mrabarnett.plus.com> - 2013-08-05 17:08 +0100
            Re: Simulate `bash` behaviour using Python and named pipes. Luca Cerone <luca.cerone@gmail.com> - 2013-08-05 09:54 -0700
              Re: Simulate `bash` behaviour using Python and named pipes. MRAB <python@mrabarnett.plus.com> - 2013-08-05 20:45 +0100
                Re: Simulate `bash` behaviour using Python and named pipes. Luca Cerone <luca.cerone@gmail.com> - 2013-08-05 14:47 -0700
                Re: Simulate `bash` behaviour using Python and named pipes. MRAB <python@mrabarnett.plus.com> - 2013-08-05 23:42 +0100
                Re: Simulate `bash` behaviour using Python and named pipes. Luca Cerone <luca.cerone@gmail.com> - 2013-08-06 09:25 -0700
                Re: Simulate `bash` behaviour using Python and named pipes. Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2013-08-10 13:07 +1200
  Re: Simulate `bash` behaviour using Python and named pipes. Alister <alister.ware@ntlworld.com> - 2013-08-05 14:29 +0000
    Re: Simulate `bash` behaviour using Python and named pipes. Luca Cerone <luca.cerone@gmail.com> - 2013-08-05 07:59 -0700
      Re: Simulate `bash` behaviour using Python and named pipes. Neil Cerutti <neilc@norwich.edu> - 2013-08-05 16:00 +0000

csiph-web