Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!lll-winken!elroy.jpl.nasa.gov!sdd.hp.com!wuarchive!rice!uw-beaver!milton!sumax!quick!amc-gw!stuart From: stuart@amc.com (Stuart Poulin) Newsgroups: comp.lang.perl Subject: Reading from /dev/tty in forked process. Message-ID: <1991May24.163027.12281@amc.com> Date: 24 May 91 16:30:27 GMT Reply-To: stuart@anabol.amc.com () Distribution: na Organization: Applied Microsystems, Redmond, WA Lines: 81 Warning: I'm new to perl. My question is how do you get perl to stop and read from /dev/tty when you have a forked process sub function that is taking its' input from STDIN. For example, say under sh I decide write a "Pager" function that prints a screen full of lines then prompts the user to hit return to get to the next screen of lines. (I'm not interested in a "Pager", I'm just using it here as an example.) I might write is as such: #!/bin/sh Pager () { PageSize=24 LineCount=1 while read i do if [ $LineCount -gt $PageSize ] if [ $LineCount -gt $PageSize ] LineCount=1 echo -n "Hit return to continue: " ( exec < /dev/tty read X ) fi echo $i LineCount=`expr $LineCount + 1 ` done } cat data | Pager #-------------------------------------------- I can then use "Pager" anywhere in the rest of the script to pump output through so it doesn't roll off the screen. Thinking along these lines I tried this perl program: #!/usr/local/bin/perl sub pager { local($pagesize,$linecount) = (24,1); open(TTYIN,") { if ( $linecount >= $pagesize ) { print "Hit return to continue: "; $ans = ; print "\n" ; $linecount = 1; } print ; $linecount++ ; } close(TTYIN); } $pid = open (OUT,"|-"); if (!$pid) { &pager; exit; } else { open(INPUT,"data") || die "Cannot open data "; while() { print OUT $_; } } This prints out the "Hit return to continue" messages but it doesn't wait for the return, it keeps on going. Most likely my problem is I'm not thinking in perl yet, but I'm tryin'. Thanks, Stuart Stuart Poulin DNS: stuart@amc.com Applied Microsystems Corporation UUCP: amc-gw!stuart Redmond, Washington 98073 Dial: 800-ASK-4AMC,206-882-2000