Operating System - HP-UX
1834137 Members
2388 Online
110064 Solutions
New Discussion

Re: Program reading input from terminal (I need to read from file or standard in)

 
Carey Goad
Occasional Advisor

Program reading input from terminal (I need to read from file or standard in)

I have a program (that a vendor wrote) which reads input from the terminal. I want to automate this job; which means reading input from a file or standard in. Unfortunately, I have not been able to get this program to redirect where it wants its input from.

Any ideas?

Thanks,
Carey Goad
carey.goad@dobson.net
7 REPLIES 7
Rick Garland
Honored Contributor

Re: Program reading input from terminal (I need to read from file or standard in)

If doing from a user standpoint:
if [ some condition ]
then
echo "Enter filename"
read filename
else
filename=$1
fi

Read can get input from a file or pipe used as standard input:
shellcommand < file
or
command|shellcommand
while read inputline
do
process inputline
done
Kofi ARTHIABAH
Honored Contributor

Re: Program reading input from terminal (I need to read from file or standard in)

have you tried the "here" construct:

cat - << EOINPUT | your_vendors_program
what the terminal would have input
somemore
EOINPUT
nothing wrong with me that a few lines of code cannot fix!
Carey Goad
Occasional Advisor

Re: Program reading input from terminal (I need to read from file or standard in)

I appreciate both of the above response; but, unfortunately neither worked. I had tried the < and << command. I did try the cat - << EOINPUT | program uncessfully.

Thanks for the ideas
Victor BERRIDGE
Honored Contributor

Re: Program reading input from terminal (I need to read from file or standard in)

Hi,
Just thoughts...
What about if your vendors program was based on reading specificaly terminal input, why not try to output your file to the terminal like cat >/dev/ttyXX?
Yours Victor
curt larson
Frequent Advisor

Re: Program reading input from terminal (I need to read from file or standard in)

#!/usr/bin/ksh

your_vendor_program |&

while read -p line
do
case $line in
"this is something I'll reply to") print -p "my respondance";;
*) continue;;
esac
done

be sure the lines you respond to are somewhat unique. At least to the point that you want to give the same answer every time.
nobody else has this problem
Carlos Fernandez Riera
Honored Contributor

Re: Program reading input from terminal (I need to read from file or standard in)

If redirection of standard input dont run:
process < file

then your program must be open your tty, so you can try try:
tty= `tty`
(sleep 1; cat file > $tty ) & process

Im not sure of syntax. The idea is feed tty whith your file.

Other:
Use glance -> proces list-> open files to see what files opens you process.







unsupported
John Palmer
Honored Contributor

Re: Program reading input from terminal (I need to read from file or standard in)

Carey,

It sounds as though your application insists on talking to the terminal - as does the passwd command.

It may be worth your while checking out 'expect' which with its dependencies tcl-8.2.1 and tk can be downloaded from your friendly neighbourhood HP Porting Centre.

Ours is http://hpux.connect.org.uk/hppd/hpux/

Quote from the porting centre:-

Expect 5.31
Allows programmed dialogue with interactive programs. Makes use of a scripting language. Can be used to automate tasks that require certain interactive responses. Requires Tcl 8.0p2, which is available in this category and can also use tk 8.0p2.

Regards,

John