ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I would like to test a connect five program by making it playing against another version of the same program.
The program takes the opponent's move via standard input and output its move via standard output.
The idea would be to redirect prog1's output to prog2's input and then redirect prog2's output to prog1's input and so on, until one of the two program exits.
It did wait for another input. You told it to read from the pipe and not from the keyboard. It read the line that you echoed in, and displayed it. Then it read from the pipe again, and got an EOF.
Perhaps we should clarify: from where did you expect the second input to come? ... cheers, makyo
from where did you expect the second input to come?
In that precise test, I would like the second input to come from the keyboard, but the first to come from the pipe.
But I would like to be able to do this:
Quote:
to redirect prog1's output to prog2's input and then redirect prog2's output to prog1's input and so on, until one of the two program exits.
I am not sure exactly how to do that, since in my test the script seems to take all its input via only one pipe, whereas I would like the program to take it from different sources (I think via a second named pipe).
Last edited by probabil1ty; 12-28-2006 at 04:16 PM.
ada@barnabas:~/tmp> cat test
#!/bin/bash
# This script is named "test"
while read
do
echo "\"test\" received \"$REPLY\"." >&2
sleep 2
echo "ping"
done
ada@barnabas:~/tmp> cat test2
#!/bin/bash
# This script is named "test2"
while read
do
echo "\"test2\" received \"$REPLY\"." >&2
sleep 2
echo "pong"
done
ada@barnabas:~/tmp> echo "ping" | ./test2
"test2" received "ping".
pong
ada@barnabas:~/tmp> mkfifo 1to2 2to1
ada@barnabas:~/tmp> ./test >1to2 <2to1 &
[3] 7678
ada@barnabas:~/tmp> ./test2 <1to2 >2to1 &
[4] 7683
ada@barnabas:~/tmp> echo "ping" > 1to2
ada@barnabas:~/tmp> "test2" received "ping".
"test" received "pong".
"test2" received "ping".
"test" received "pong".
"test2" received "ping".
"test" received "pong".
"test2" received "ping".
"test" received "pong".
"test2" received "ping".
"test" received "pong".
"test2" received "ping".
[...]
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.