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.
2 Answers
./a.out << EOF
first line of input
second line of input
EOF
-
1@ValentinRadu If you want to read more about this feature, it's called a heredoc or here-document.Gilles 'SO- stop being evil'– Gilles 'SO- stop being evil'09/30/2011 23:19:57Commented Sep 30, 2011 at 23:19
-
Cool, I see that you can use any kind of "tags" not only
EOF
. Thanks!Rad'Val– Rad'Val10/01/2011 07:43:44Commented Oct 1, 2011 at 7:43 -
Yes, but EOF is the convention, unless you think your input might have have that string in it.Paul Tomblin– Paul Tomblin10/01/2011 12:22:52Commented Oct 1, 2011 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.
-
Seems cool, but it's more than what I need:)Rad'Val– Rad'Val09/30/2011 12:29:19Commented Sep 30, 2011 at 12:29