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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

(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

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


And call binary like this :

binary < in.txt
share|improve this answer

Your Answer


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.