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

2013-08-09 Thread Gregory Ewing
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 = subp

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

2013-08-06 Thread Luca Cerone
> my_thread.join() Thanks! I managed to make it work using the threading library :) -- http://mail.python.org/mailman/listinfo/python-list

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

2013-08-05 Thread MRAB
On 05/08/2013 22:47, Luca Cerone wrote: You're back to using separate threads for the reader and the writer. And how do I create separate threads in Python? I was trying to use the threading library without not too success.. To run a function in a separate thread: import threading def my_f

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

2013-08-05 Thread Luca Cerone
> You're back to using separate threads for the reader and the writer. > And how do I create separate threads in Python? I was trying to use the threading library without not too success.. -- http://mail.python.org/mailman/listinfo/python-list

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

2013-08-05 Thread MRAB
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

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

2013-08-05 Thread Luca Cerone
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_proc

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

2013-08-05 Thread Neil Cerutti
On 2013-08-05, Luca Cerone wrote: > I just would like to learn how to handle named pipes in Python, > which I find it easier to do by using a simple example that I > am comfortable to use :) Names pipes are a unix concept that saves you the hassle and limitations of writing to and reading from a

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

2013-08-05 Thread MRAB
On 05/08/2013 16:27, Luca Cerone wrote: Thanks MRAB, You need to ensure that the pipe is already open at the other end. So I need to open the process that reads the pipe before writing in it? Why are you using a named pipe anyway? For some bug in ipython (see my previous email) I can't u

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

2013-08-05 Thread Luca Cerone
Thanks MRAB, > > You need to ensure that the pipe is already open at the other end. So I need to open the process that reads the pipe before writing in it? > > > > Why are you using a named pipe anyway? For some bug in ipython (see my previous email) I can't use subprocess.Popen and pipe in

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

2013-08-05 Thread Luca Cerone
Hi Alister, > Are you sure you are using the correct tool for the task? Yes. For two reasons: 1. I want to learn how to do this in Python :) 2. for an application I have in mind I will need to run external tools (not developed by me) and process the output using some tools that I have written in

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

2013-08-05 Thread MRAB
On 05/08/2013 15:11, Luca Cerone wrote: Hi MRAB, thanks for the reply! Opening the pipe for reading will block until it's also opened for writing, and vice versa. OK. In your bash code, 'ls' blocked until you ran 'cat', but because you ran 'ls' in the background you didn't notice it! R

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

2013-08-05 Thread Alister
On Mon, 05 Aug 2013 06:09:53 -0700, Luca Cerone wrote: > Hi everybody, > I am trying to understand how to use named pipes in python to launch > external processes (in a Linux environment). > > As an example I am trying to "imitate" the behaviour of the following > sets of commands is bash: > >>

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

2013-08-05 Thread Luca Cerone
Hi MRAB, thanks for the reply! > > Opening the pipe for reading will block until it's also opened for > > writing, and vice versa. > OK. > > > In your bash code, 'ls' blocked until you ran 'cat', but because you > > ran 'ls' in the background you didn't notice it! > > Right. > > In your

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

2013-08-05 Thread MRAB
On 05/08/2013 14:09, Luca Cerone wrote: Hi everybody, I am trying to understand how to use named pipes in python to launch external processes (in a Linux environment). As an example I am trying to "imitate" the behaviour of the following sets of commands is bash: mkfifo named_pipe ls -lah >

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

2013-08-05 Thread Luca Cerone
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

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

2013-08-05 Thread Paul Wiseman
On 5 August 2013 14:09, Luca Cerone wrote: > Hi everybody, > I am trying to understand how to use named pipes in python to launch > external processes (in a Linux environment). > > As an example I am trying to "imitate" the behaviour of the following sets > of commands is bash: > > > mkfifo named

Simulate `bash` behaviour using Python and named pipes.

2013-08-05 Thread Luca Cerone
Hi everybody, I am trying to understand how to use named pipes in python to launch external processes (in a Linux environment). As an example I am trying to "imitate" the behaviour of the following sets of commands is bash: > mkfifo named_pipe > ls -lah > named_pipe & > cat < named_pipe In Pyt