It probably will get more complicated than you want. You want to intercept the q keypress.
Here is a simple example, (or you can move up to an eventloop system, or watch STDIN in the separate thread, and let it watch for q). I 'm not sure how to pass the q to killing your command , unless you use a piped open or some other IPC module that returns a pid. Maybe someone knows a clever trick for that using return values from system.
#!/usr/bin/perl use warnings; use strict; use Term::ReadKey; #passing ReadKey() an argument of -1 to indicate not to block: ReadMode('cbreak'); while(1){ my $char; if (defined ($char = ReadKey(0)) ) { print "$char->", ord($char),"\n"; # input was waiting and i +t was $char if(ord($char) == 113){ print "Got a q\n"; print "Do your thing + here\n" } if(ord($char) == 27){ print "Got an Escape\n"; exit; } } else { # no input was waiting } } ReadMode('normal'); # restore normal tty settings
In reply to Re: How to know whether user terminates system("$cmd|more") with q or not?
by zentara
in thread How to know whether user terminates system("$cmd|more") with q or not?
by PerlOnTheWay
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |