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 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 ?

share|improve this question
add comment

2 Answers

up vote 5 down vote accepted

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.

share|improve this answer
add comment

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
share|improve this answer
add comment

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.