Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hi, I have a script, named "scri

Status
Not open for further replies.

jialian

Programmer
Jan 4, 2002
6
US
Hi,

I have a script, named "script1", which reads from STDIN:
print STDERR "Enter a character:";
open STDIN, "/dev/tty" or warn "couldn't open /dev/tty $!\n";
my($c);
$c = getc(STDIN);

There is a unix shell script, named "script2", containing:
script1

Without changing the first script, is there a way to read a file for the input. I have tried using:
script1 < /dir/input_filename
also tried:
script1 &0< /dir/input_filename
and tried:
script1 << EOF
x
EOF
but it does not work. Is there a way to set STDIN to obtain input from a file and then set it back to accept input from the keyboard?

Thanks,
JL :)
 
This is only a guess, I am not sure about it.
You are trying to have STDIN reference a given file and then you call script1.
But in script1, we find this instruction:
Code:
open STDIN, &quot;/dev/tty&quot; or warn &quot;couldn't open /dev/tty $!\n&quot;;
. Doesn't it force STDIN to the terminal's keyboard?
 
Thanks for your reply. Yes ... open STDIN does force it to the terminal's keyboard. Someone else wrote &quot;script1&quot; (there is other logic in it) and I wanted to reuse in it without changing it so I was wondering if there were any unix shell script command that can change STDIN to read from a file without changing &quot;script1&quot;. I guess that there was no way to get around this without changing &quot;script1&quot;.

Thanks for your help,
JL


 
Here's another guess.

cat somefile|script1

Robert Robert G. Jordan
Unix Sys Admin
Sleepy Hollow, Illinois U.S.A.
sh.gif


FREE Unix Scripts
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top