0

I'm trying to use named pipes in a project. I have two terminals open, Terminal A and Terminal B.

In terminal A, I issued this command:

mkfifo myFifo && tail -f myFifo | csh -s

It seems as if standard out is being redirected somewhere else, though, because my prompt disappears and some commands aren't reflected in terminal A.

For example, if in terminal B I begin a python session via issuing echo "python" > myFifo, then echo "print 'Hello, World'" > myFifo, I don't see Hello, World in terminal A.

However, if I issue echo ls > myFifo within terminal B, I see the correct output from ls in terminal A.

Does anyone know why sometimes the output appears and sometime it doesn't?

I'm running on CentOS 6.6

Thanks, erip

erip
  • 16,374
  • 11
  • 66
  • 121

1 Answers1

0

You read from the FIFO with csh, if you start an interactive Python shell in csh, then it won't be reading from the FIFO because it's busy running python.

Python doesn't somehow automagically do a REPL on the FIFO. How should it even know about the FIFO? It has no knowledge of it.

You could, perhaps, tell Python to read commands from the FIFO with something like:

>>> import os, sys, time
>>> fifo = open(os.open('myFifo',  os.O_NONBLOCK), 'r')

And then:

$ echo 'print(42+5)' > ! myFifo  

Will give you:

>>> eval(fifo.read())
47

Perhaps there's also a way to tell Python to read commands from myFifo by overwriting sys.stdin, but I can't get that working in my testing.

It's a bit unclear to me what exactly you're trying to achieve here, though. I suspect there might be another solution which is much more appropriate to the problem you're having.

Martin Tournoij
  • 26,737
  • 24
  • 105
  • 146