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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I timeout a "read" command

Status
Not open for further replies.

Tison

Programmer
May 12, 1999
216
0
0
CH
I want to give the users 10 seconds to press the "ENTER" key.If they do not press "ENTER", perform task A , else if they do press "ENTER", perform task B.
My problem is in getting the "read" command to continue after the 10 seconds have elapsed.
 
Can't do it. Since "read" is an internal command to "ksh", there is no sub-process spawned off to check for in the process table (ps -ef), so you can't kill it.

You'll need to write some sort of C program. Perl might be able to do this as well, but I'm not sure.

Bill.
 
Try using expect in Perl. It has timeouts and all kinds of neat stuff. I automate alot of telnet/ftp sessions with this tool and reads probably wouldn't be that difficult either.

-------------snip------------------------
#!/usr/bin/perl -w

use Expect;

$command = Expect->spawn("telnet zeus") || die "no telnet";

unless($command->expect(10, "login: ")) {
# timed out
}
print $command &quot;<loginName>\r&quot;;
-------------endsnip---------------------

something like this...

hope it helps.






 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top