Can I hook a "file" to a python script?

Scott Chapman scott_list at mischko.com
Sat Nov 8 11:55:22 EST 2003


On Saturday 08 November 2003 02:01, Mathias Waack wrote:
> Scott Chapman wrote:
> > I'd like a "file" on the Linux box to actually be the input and
> > output
> > of a Python script.  Anything written to the file would be sent to
> > a database and anything read from the file would come from the
> > database. I know how to do the database end of this but I'm not
> > sure if a script
> > can be hooked to a "file" transparently.  The script would probably
> > have to be run as a daemon.  I doubt there's enough magic in the
> > Linux world to make it so that a read/write would actually launch
> > the script. That'd be Ok.
>
> The solution is very easy. There are at least two ways. First the
> easier one: create a named pipe using mkfifo(1) and start your
> python script which should attach itself to one end of the pipe. The
> second solution is bit more complex: you need a new device. The
> device driver will only forward all input to your user space daemon
> or read all output from it. This way your python script can be
> started automagically each time someone accesses the device special
> file.

I understand named pipes to be "one-way" only.  Is that correct?

Scott





More information about the Python-list mailing list