Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a C program in which I use scanf to get user input. Now, I would like to make a .sh script that automatically test this program with pre-defined user input, but I'm not sure how I can send the input every time the program needs it.

share|improve this question

2 Answers 2

up vote 7 down vote accepted
./a.out << EOF
first line of input
second line of input
EOF
share|improve this answer
    
This works fine! Thank you! –  Valentin Radu Sep 30 '11 at 12:26
1  
@ValentinRadu If you want to read more about this feature, it's called a heredoc or here-document. –  Gilles Sep 30 '11 at 23:19
    
Cool, I see that you can use any kind of "tags" not only EOF. Thanks! –  Valentin Radu Oct 1 '11 at 7:43
    
Yes, but EOF is the convention, unless you think your input might have have that string in it. –  Paul Tomblin Oct 1 '11 at 12:22

If you need to have an automated conversation with your program (i.e. want to interpret the output as well), take a look at expect. This is a tcl based tool for automating interactive sessions. It might give you what you want.

share|improve this answer
    
Seems cool, but it's more than what I need:) –  Valentin Radu Sep 30 '11 at 12:29

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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