Simulate `bash` behaviour using Python and named pipes.
Luca Cerone
luca.cerone at gmail.com
Mon Aug 5 11:27:46 EDT 2013
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 the standard way.
One of Ipython developers has suggested me to use named pipes as a temporary workaround. So I am taking the occasion to learn :)
>
> If you're talking to another program, then that needs to be running
>
> already, waiting for the connection, at the point that you open the
>
> named pipe from this end.
I am not entirely sure I got this: ideally I would like to have a function that runs an external tool (the equivalent of ls in my example) redirecting its output in a named pipe.
A second function (the cat command in my example) would read the named_pipe, parse it and extract some features from the output.
I also would like that the named_pipe is deleted when the whole communication is ended.
>
> If you're using a pipe _within_ a program (a queue would be better),
>
> then you should opening for writing in one thread and for reading in
>
> another.
Let's stick with the pipe :) I will ask about the queue when I manage to use pipes ;)
I should have explained better that I have no idea how to run threads in Python :): how do I open a thread that executes "ls -lah" in background and writes into a named pipe? And how do I open a thread that reads from the named pipe?
Can you please post a small example, so that I have something to work on?
Thanks a lot in advance for your help!
Luca
More information about the Python-list
mailing list