Keeping a pipe (named or otherwise) open between programs

1's picture


Consider the situation in which you have an interpreter program and an editor (not emacs, otherwise i wouldn't have been asking this question).

I'd like to have a situation where the interpreter can read from a pipe, or a file, while i edit the a program and feed it, perhaps via pipe
to this pipe from time to time. So:

let there be a named pipe called .. 'apipe'

i'd like something of form to happen :

$ mkfifo apipe
$ interpreter < apipe

and in another terminal

(editing the script ...)
$cat script > apipe
(continue editing ...)
$cat script > apipe
all the time keeping apipe open, so that the 'interpreter' does not terminate.

Is this possible? I am interested in any solution which would allow me to feed output from some program to another from time to time, without closing the interpreter in between the feeds.


1's picture

I came up with this solution.

Firstly, I wrap up the interpreter in a script:
while :
cat xxx

As before, the interpreter is a program i want to be able to interactively control and xxx is a named pipe (created by mkfifo xxx).

After starting the script in one terminal, I open my editor, edit a program, and whenever I want the interpreter to evaluate the
contents I just write the program's buffer to the pipe xxx. Running instance of the interpreter is being constantly fed from the pipe through the while loop,
so I can interactively develop a program without a need of running every changed version through a new instance of interpreter. Also, if my editor
is clever enough, I could send only new lines of code through the pipe to be evaluated.

As a more concrete application of this , I am using vim editor to write Scheme code and while i develop the program I feed it interactively to open instance of the guile interpreter.
The same thing could be done for python, or whatever else one would want.
Of course, you can avoid all this if you use an appropriate emacs mode, but, then, I am a vim guy.

If somebody has a cleverer idea how to solve this interesting problem (what about a bash 4 coroutine?) please leave your comment.