Operating System - HP-UX
1834842 Members
2219 Online
110070 Solutions
New Discussion

run the program with batch mode

 
peterchu
Super Advisor

run the program with batch mode


I have installed a program (eg. programA ), if the user run the program , it will ask the user to answer some questions ( assume all the answers are "yes" ), for simplier , is it possible to answer all the questions automatically by a batch mode ? so that the user no need to input many many times of "yes" thx in advance.
eg.
#run programA < answer.txt , where answer.txt contain the word "yes" .
7 REPLIES 7
Keith Bryson
Honored Contributor

Re: run the program with batch mode

Hi there

If you run the program from a script, you should be able to do something like this:

#----- start of script -----
#!/bin/ksh
/myprogram <
Arse-cover at all costs
Peter Godron
Honored Contributor

Re: run the program with batch mode

Hi,
but be careful if the program you are calling is rm.
I just tried:
touch a.txt
chmod 444 a.txt
ll a.txt
rm a.txt << !
n
!
ll a.txt
AND THE FILE HAD BEEN REMOVED !
Keith Bryson
Honored Contributor

Re: run the program with batch mode

Peter (Gordon) - that's probably because rm wouldn't have prompted you anyway? rm -i would have (you are the owner of the file).

Keith
Arse-cover at all costs
Peter Godron
Honored Contributor

Re: run the program with batch mode

Keith,
I tried the same rm from the command line and it responded with:
a.txt: 444 mode ? (y/n)

My note was purely a by-the-way, your solution is absolutely correct ;-)
Keith Bryson
Honored Contributor

Re: run the program with batch mode

Hi Peter(s)!

No worries. My rm doesn't behave like that by default, maybe we are using different flavours of Unix (I know Linux prompts for everything!).

Anyway, peter(chu) hope this has sorted your problem.

All the best - Keith
Arse-cover at all costs
Matthew_50
Valued Contributor

Re: run the program with batch mode

try 'expect' scripting.
Mohanasundaram_1
Honored Contributor

Re: run the program with batch mode

Hi Peterchu,

If all the user inputs are going to be "yes", then why should the script ask a question, in the first place?

Your script can be made to run with all the "yes" conditions as the assumed answer.

WIth regards,
Mohan.
Attitude, Not aptitude, determines your altitude