I've got a C program that reads from stdin and does some operations. I am asked to enter information periodically (every 20 sec), and leave the user interaction the same while doing some tests.

Is this possible without modifing the C program? I have already done a shell script that echoes the information periodically (to its stdout), so the idea is to connect this shell and the normal stdin to only one stdin (an inverse tee).

I tried (./periodic.sh; cat) > ./myprogram , which doesn't work because it is waiting the script to end (and the same the other way round).

  • Yes, that is what I want, but I also want to use "normal" stdin (keyboard writing) to "myprogram". I want both entries to the program.
    – markmb
    Apr 1, 2014 at 7:23

2 Answers 2


To accomplish this you can use a "socket" in the middle. You would setup a socket file (e.g. /tmp/program.socket and then adapt your program to read from that instead of stdin.

Then you can have as many programs as needed writing to said socket.

  • I wanted to avoid modifying the program. I tried with a pipe and shell commands, but I have not been able to achieve the results I want (everything gets mixed at the end). If I can't find a solution, I'll modify the program.
    – markmb
    Apr 1, 2014 at 10:03

Your script is not working, not because "./myprogram" is waiting for your script to end, but because "./myprogram" is waiting for the indefinite "cat" to end you started in your subshell "( ... )".

Even though your question is very vague, I'm guessing you need to learn how to use pipes.

mkfifo mypipe
while true; do
    ./periodic.sh > mypipe &
    ./myprogram < mypipe

This code will forever wait for your input to "./periodic.sh", once you provide that, it will be passed to the pipe "mypipe" (in the background), then "./myprogram" will process it's output.

Hope this is what you've been looking for. As I said before, your question is a little vague.

Have fun.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.