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


Groups > comp.lang.python > #51959

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

Newsgroups comp.lang.python
Date 2013-08-05 06:51 -0700
References <a4c08e1c-2915-48ed-a65d-2e1b89f28878@googlegroups.com> <mailman.208.1375709966.1251.python-list@python.org>
Message-ID <0b3fcb71-ce96-4f7e-b765-dff61bbdb119@googlegroups.com> (permalink)
Subject Re: Simulate `bash` behaviour using Python and named pipes.
From Luca Cerone <luca.cerone@gmail.com>

Show all headers | View raw


Hi Paul, first of all thanks for the help.

I am aware of the first solutions, just now I would like to experiment a bit with  using named pipes (I also know that the example is trivial, but it just to grasp the main concepts)

> 
> You can also pass a file object to p1's stdout and p2's stdin if you want to >pipe via a file.
 
> 
> with open("named_pipe", "rw") as named_pipe:
>     p1 = subprocess.Popen(["ls", "-lah"], stdout=named_pipe)
>     p2 = subprocess.Popen(["cat"], stdin=named_pipe)
> 
>     p1.wait()
>     p2.wait()
>  

Your second example doesn't work for me.. if named_file is not a file in the folder I get an error saying that there is not such a file.

If I create named_pipe as a named pipe using os.mkfifo("named_file",0777) than the code hangs.. I think it is because there is not process that reads the
content of the pipe, so the system waits for the pipe to be emptied.

Thanks a lot in advance for the help in any case.
Luca

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