So I am attempting to make a script to automate the testing(in and out) of my C program and I am trying to get the input to stay on screen so I know what is happening.
I have only tried piping so far:
foo < input.txt
and
cat input.txt | tee dev/tty |foo
which has yet to work for me.
So assuming the input file would look like:
123
321
Ideally, the IO would look like:
Input: 123
Echo: 123
Input: 321
Echo: 321
but it turns into
123
321
Input:
Echo: 123
Input:
Echo: 321
Are there other methods that I can use to test my C program? Where else can I tee to that can achieve such result? Is it possible for me to write another C program that can achieve something similar?
The stdout of tee
(to stdin of foo
) and the duplicated writes (to your tty
character dev) are not synchronized in time. Your tty is consuming input faster than foo
and the buffering of libc is making it even worse. If interactive automation is what you seek, look to the expect
program.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With