Search code examples
linuxbashconsole

Is there a way to connect two programs output/input in linux?


I have two programs (p1 and p2), and I need to connect the p1 output to p2 input, and the p2 output to p1 input. Is there a way to do this?

The 'why' is because I have two programs that will play a game, so the first program will do a move and wait to receive a move from the other program and so on. The end of execution will be when the first program exit with signal 0 or 1. The program p1 will always be the same, but the p2 will change over every iteration.

I need to do this in linux terminal, because the programs p1 and p2 can be (and probably will be) executed in different languages, like p1 will be c++ executable and p2 will be a python script.


Solution

  • You can use the socat utility:

    socat -v exec:p1 exec:p2
    

    The -v is optional and shows the chatter back and forth for your debugging and enjoyment.