Operating System - HP-UX
1847702 Members
5587 Online
110265 Solutions
New Discussion

Passing valu to a menu driven program

 
Shahul
Esteemed Contributor

Passing valu to a menu driven program

Hi,

I have an executable file which is a menu driven program. I need to select certain option in the menu. For eg

#/usr/sbin/foo

Now one menu will appear with some options
1.abcd
2.efgh
3.ijkl
4.mnop
0.Exit

Enter your choice>

I need to select 2, and the 1 in the submenu and then 0 to exit. Can this selection be automated in a script?

Replys are higly appreciated.

TIA
Shahul
5 REPLIES 5
Pete Randall
Outstanding Contributor

Re: Passing valu to a menu driven program


PS3="Enter your choice> "
select answer in "1.abcd" "2.efgh" "3.ijkl" "4.mnop" "0.Exit"
do
case $answer in
"1.abcd" )
;;
"2.efgh" )
;;
"3.ijkl" )
;;
"4.mnop" )
;;
"0.Exit" )
exit 0;;
* )
echo "invalid choice"
esac
done


Pete

Pete
Shahul
Esteemed Contributor

Re: Passing valu to a menu driven program

Hi Pete,

Thanks for your response. I think you did not get it right/ I did not put it right. The menu with 0 to 4 option is displayed by an executable program, ie. /usr/sbin/foo. I can not change this executable. I want to select certain options from that menu. Manually I am able to select through keyboard, My question is, can I automate this by using a value / parameter?

Regards
Shahul
Robert Salter
Respected Contributor

Re: Passing valu to a menu driven program

You mean like a script with the contents;
/usr/sbin/foo <2
1
0
EOF

So it will select 2, then 1, then 0.
Time to smoke and joke
Patrick Wallek
Honored Contributor

Re: Passing valu to a menu driven program

If Robert's suggestion does not work, the you will need to take a look at Expect. Expect is a programming / scripting language that is designed to do just what you require.

You can download Expect from here:
http://hpux.connect.org.uk/hppd/hpux/Tcl/expect-5.43/
Amit Agarwal_1
Trusted Contributor

Re: Passing valu to a menu driven program

If you are interested in automating the interactive session, you can use either 'expect' or 'vuser' facility. I don't think they are available by default, you might need to search them on website. 'expect' is much better/powerful tool than 'vuser'