How to "cross"
stdout of two programs? Specifically, I have 2 programs call
pgm2, they are interactive tic-tac-toe games. They both output a number (0to8) indicating position where it wants to mark and expect another number (0to8) indicating where the user wants to mark. The difference between the two is
pgm1 makes first move and
pgm2 makes second move. They both work fine via interactive user. Can they be made to play against each other using io redirection?
I tried the following things in vain:
pgm2in a separate terminal (it waits for input), find it's pid. Then run
pgm1in another terminal
./pgm1 < /proc/pid_pgm2/fd/1 > /proc/pid_pgm2/fd/0
- Made 2 pipes using mkfifo, say
pipe2and ran the following in two different terminals:
./pgm1 < pipe1 > pipe2and
./pgm2 < pipe2 > pipe1
- tried the above two, running pgm1 before pgm2, running pgm2 before pgm1
I made sure to use
fflush(stdout)in both the programs, immediately after using
Could anyone tell me what i am missing / or going wrong / or is this even possible?