dbm
dbm

Reputation: 159

Shell script to call external program which has user-interface

I have an external program, say a.out, which while running asks for an input parameter, i.e.,

./a.out

Please select either 1 or 2:

  1. this will do something

  2. this will do something else


Then when I enter '1', it will do its job. I don't have the code itself but just binary so can't change it. I want to write a shell script which runs a.out and also inserts '1' in.

I tried many things including silly things like:

./a.out 1

./a.out << 1

./a.out < 1

etc.

but don't work. Could you please let me know if there is any way to write such as shell script? Thanks, dbm368

Upvotes: 0

Views: 767

Answers (1)

Brian McFarland
Brian McFarland

Reputation: 9422

I think you just need a pipe. For example:

echo 1 | ./a.out

In general terms a pipe takes whatever the program on the left writes to stdout and redirects to the stdin of the program on the right.

Upvotes: 1

Related Questions