4

I have a binary file on Unix, which when executed asks the user for inputs. The inputs to this binary file are given manually. I want to automate the procedure, since I know the inputs already. I can't modify the binary file. How can I do this ? Is this possible via shell script or even with ant targets ?

2 Answers 2

6

If the program reads from standard input (as opposed to direct from the terminal), you could do something like

echo -e "answer1\nanswer2\nanswer3\n" | your_program

A here document may be more readable:

your_program <<'EOF'
answer1
answer2
answer3
EOF
do_more_stuff

(You can pick any string instead of EOF, just make sure to use the same in <<'somestring' and to mark the end of the input. The string must not appear as an input line. The end-of-input mark must not be indented.)

If you need more complex interaction then an expect script is what you want.

2

If you have many inputs, you can also put these inputs into a file

in.txt:
input1
input2
...
intputn

And call binary like this :

binary < in.txt

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .