Is it possible to make a custom REPL (for e.g. python) with two fifos?
Explanation of the problem
Suppose I have two fifos
out. I have three terminals.
- In the first I want to run commands that output python code to
in. For example
echo "print(1+2)" > in echo "a = 3" > in echo "b = 4" > in // wait some time # usual comments break SO formatting echo "print(a*b)" > in
- The second just runs
cat out. The result should be something like
3 // wait a little time <-- of course this is not real output 12
- The third should read
inrun the lines through
pythonand print the result to
outjust like in a usual interactive python session.
Attempt at a solution / further remarks
- Just running
python in >outin the third terminal does not work. It terminates after the first line is written to
in, the second terminal will only print the
- Writing a wrapper that tries to run lines from
evaldoes not work, because I need to be able to parse lines like
import sys, or the likes.
- All in all, I really want the behaviour of the standard REPL of python, except that I do not want to be sitting at the keyboard and putting in lines, one by one. I want to be able to change the input and output channels.