Sponsored Content
Top Forums Shell Programming and Scripting Perl | catching the letter 'Q' for exit. Post 302420932 by deindorfer on Thursday 13th of May 2010 01:41:41 AM
Old 05-13-2010
Perl: Unbuffered Keyboard Read to Exit Running Code

Code:
use Term::ReadKey;
ReadMode 4;

until ( ReadKey(-1) eq 'Q' ) {
   ... Your Program Here ...
}

ReadMode 0; # Reset tty before exiting
exit;

There you are, sir.
This User Gave Thanks to deindorfer For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

PERL: Trapping EXIT

Hey Everyone, Just starting with PERL (5.8.2) after years of KSH. Is there a way to trap the exit as you can in KSH (i.e., "trap EXIT_SCRIPT EXIT")? Thanks in advance for any help, gsatch (4 Replies)
Discussion started by: gsatch
4 Replies

2. Shell Programming and Scripting

How to get exit status codes in bash from Perl?

I apologize if I have already posted this query. I scanned back quite a few pages but could not find such a query. If my perl code contains "exit(33)" how can I get that value in bash for use in a "if" statement. Thanks, Siegfried (5 Replies)
Discussion started by: siegfried
5 Replies

3. Shell Programming and Scripting

Catching all Exit Codes

I have a Unix Script that has several exit in the middle. each returning seperate exit codes. I have to catch all the exit's and perform an operation say "Mail the status code" before the actual code completes. How can i do this in KSH ? (3 Replies)
Discussion started by: Sivaswami J
3 Replies

4. Shell Programming and Scripting

exit ststus 9 from perl system command

HI all, can anyone tell me what does exit status 9 from perl's system function meant. I am using system fuction to execute a shell script as : my $s=system ('script.sh' ,arg1 ,arg2); print $s; the output is 9. Thanks in advance. !!:confused: (1 Reply)
Discussion started by: glamo_2312
1 Replies

5. Shell Programming and Scripting

Letter Frequency Decryption Program in Perl

Hello, :/ (0 Replies)
Discussion started by: jvr42
0 Replies

6. Shell Programming and Scripting

Perl Question Grep and exit status

Im being forced to write in perl. I prefer KSH or Expect, so I suppose its time to become more fluent with perl. I have the following problem. I want to loop through Filea and check that each line in Filea is resident in Fileb. Filea contents two four six eight houseboat Fileb... (4 Replies)
Discussion started by: sumguy
4 Replies

7. Shell Programming and Scripting

[Solved] Perl, Deep recursion? exit() ignored?

Hi all, I am calling a subroutine which checks if a log file is writeable and if not, prints something stdout and also log something into the same file, which doesn't work neither of course. Anyway, there is enough exit() calls, that should stop it working, but the problem is, that I get the... (5 Replies)
Discussion started by: zaxxon
5 Replies

8. Shell Programming and Scripting

Issue catching/reading 2 digits and 3 letter string between brackets

Hello I'm writing a handler for ffmpeg, and having troubles to catch some exceptions that may occour with certain files. In order to parse for video & subtitle maps, i've had to make the raw data easier to handle, until now this worked well, but basicly i've just been lucky... The input... (1 Reply)
Discussion started by: sea
1 Replies

9. Shell Programming and Scripting

Replace specific letter in a file by other letter

Good afternoon all, I want to ask how to change some letter in my file with other letter in spesific line eg. data.txt 1 1 1 0 0 0 0 for example i want to change the 4th line with character 1. How could I do it by SED or AWK. I have tried to run this code but actually did not... (3 Replies)
Discussion started by: weslyarfan
3 Replies

10. Programming

Perl: trap signal 'exit': why I am not able to have it work??

First time trying to work with signals in Perl. Reviewing example I try it, but not able to get it work for 'exit'. I hope, I am correct, assuming, that the ending any code by exit $return_code; the $SIG{EXIT} should be de-referenced and processed?! So, I have such code, that, I assume,... (5 Replies)
Discussion started by: alex_5161
5 Replies
ReadKey(3)						User Contributed Perl Documentation						ReadKey(3)

NAME
Term::ReadKey - A perl module for simple terminal control SYNOPSIS
use Term::ReadKey; ReadMode 4; # Turn off controls keys while (not defined ($key = ReadKey(-1))) { # No key yet } print "Get key $key "; ReadMode 0; # Reset tty mode before exiting DESCRIPTION
Term::ReadKey is a compiled perl module dedicated to providing simple control over terminal driver modes (cbreak, raw, cooked, etc.,) support for non-blocking reads, if the architecture allows, and some generalized handy functions for working with terminals. One of the main goals is to have the functions as portable as possible, so you can just plug in "use Term::ReadKey" on any architecture and have a good likelihood of it working. Version 2.30.01: Added handling of arrows, page up/down, home/end, insert/delete keys under Win32. These keys emit xterm-compatible sequences. Works with Term::ReadLine::Perl. ReadMode MODE [, Filehandle] Takes an integer argument, which can currently be one of the following values: 0 Restore original settings. 1 Change to cooked mode. 2 Change to cooked mode with echo off. (Good for passwords) 3 Change to cbreak mode. 4 Change to raw mode. 5 Change to ultra-raw mode. (LF to CR/LF translation turned off) Or, you may use the synonyms: restore normal noecho cbreak raw ultra-raw These functions are automatically applied to the STDIN handle if no other handle is supplied. Modes 0 and 5 have some special properties worth mentioning: not only will mode 0 restore original settings, but it cause the next ReadMode call to save a new set of default settings. Mode 5 is similar to mode 4, except no CR/LF translation is performed, and if possible, parity will be disabled (only if not being used by the terminal, however. It is no different from mode 4 under Windows.) If you are executing another program that may be changing the terminal mode, you will either want to say ReadMode 1 system('someprogram'); ReadMode 1; which resets the settings after the program has run, or: $somemode=1; ReadMode 0; system('someprogram'); ReadMode 1; which records any changes the program may have made, before resetting the mode. ReadKey MODE [, Filehandle] Takes an integer argument, which can currently be one of the following values: 0 Perform a normal read using getc -1 Perform a non-blocked read >0 Perform a timed read (If the filehandle is not supplied, it will default to STDIN.) If there is nothing waiting in the buffer during a non-blocked read, then undef will be returned. Note that if the OS does not provide any known mechanism for non-blocking reads, then a "ReadKey -1" can die with a fatal error. This will hopefully not be common. If MODE is greater then zero, then ReadKey will use it as a timeout value in seconds (fractional seconds are allowed), and won't return "undef" until that time expires. (Note, again, that some OS's may not support this timeout behaviour.) If MODE is less then zero, then this is treated as a timeout of zero, and thus will return immediately if no character is waiting. A MODE of zero, however, will act like a normal getc. There are currently some limitations with this call under Windows. It may be possible that non-blocking reads will fail when reading repeating keys from more then one console. ReadLine MODE [, Filehandle] Takes an integer argument, which can currently be one of the following values: 0 Perform a normal read using scalar(<FileHandle>) -1 Perform a non-blocked read >0 Perform a timed read If there is nothing waiting in the buffer during a non-blocked read, then undef will be returned. Note that if the OS does not provide any known mechanism for non-blocking reads, then a "ReadLine 1" can die with a fatal error. This will hopefully not be common. Note that a non-blocking test is only performed for the first character in the line, not the entire line. This call will probably not do what you assume, especially with ReadMode's higher then 1. For example, pressing Space and then Backspace would appear to leave you where you started, but any timeouts would now be suspended. This call is currently not available under Windows. GetTerminalSize [Filehandle] Returns either an empty array if this operation is unsupported, or a four element array containing: the width of the terminal in characters, the height of the terminal in character, the width in pixels, and the height in pixels. (The pixel size will only be valid in some environments.) Under Windows, this function must be called with an "output" filehandle, such as STDOUT, or a handle opened to CONOUT$. SetTerminalSize WIDTH,HEIGHT,XPIX,YPIX [, Filehandle] Return -1 on failure, 0 otherwise. Note that this terminal size is only for informative value, and changing the size via this mechanism will not change the size of the screen. For example, XTerm uses a call like this when it resizes the screen. If any of the new measurements vary from the old, the OS will probably send a SIGWINCH signal to anything reading that tty or pty. This call does not work under Windows. GetSpeeds [, Filehandle] Returns either an empty array if the operation is unsupported, or a two value array containing the terminal in and out speeds, in decimal. E.g, an in speed of 9600 baud and an out speed of 4800 baud would be returned as (9600,4800). Note that currently the in and out speeds will always be identical in some OS's. No speeds are reported under Windows. GetControlChars [, Filehandle] Returns an array containing key/value pairs suitable for a hash. The pairs consist of a key, the name of the control character/signal, and the value of that character, as a single character. This call does nothing under Windows. Each key will be an entry from the following list: DISCARD DSUSPEND EOF EOL EOL2 ERASE ERASEWORD INTERRUPT KILL MIN QUIT QUOTENEXT REPRINT START STATUS STOP SUSPEND SWITCH TIME Thus, the following will always return the current interrupt character, regardless of platform. %keys = GetControlChars; $int = $keys{INTERRUPT}; SetControlChars [, Filehandle] Takes an array containing key/value pairs, as a hash will produce. The pairs should consist of a key that is the name of a legal control character/signal, and the value should be either a single character, or a number in the range 0-255. SetControlChars will die with a runtime error if an invalid character name is passed or there is an error changing the settings. The list of valid names is easily available via %cchars = GetControlChars(); @cnames = keys %cchars; This call does nothing under Windows. AUTHOR
Kenneth Albanowski <kjahds@kjahds.com> Currently maintained by Jonathan Stowe <jns@gellyfish.co.uk> SUPPORT The code is maintained at https://github.com/jonathanstowe/TermReadKey Please feel free to fork and suggest patches. LICENSE Prior to the 2.31 release the license statement was: Copyright (C) 1994-1999 Kenneth Albanowski. 2001-2005 Jonathan Stowe and others Unlimited distribution and/or modification is allowed as long as this copyright notice remains intact. And was only stated in the README file. Because I believe the original author's intent was to be more open than the other commonly used licenses I would like to leave that in place. However if you or your lawyers require something with some more words you can optionally choose to license this under the standard Perl license: This module is free software; you can redistribute it and/or modify it under the terms of the Artistic License. For details, see the full text of the license in the file "Artistic" that should have been provided with the version of perl you are using. This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose. POD ERRORS
Hey! The above document had some coding errors, which are explained below: Around line 213: '=item' outside of any '=over' =over without closing =back perl v5.18.2 2013-10-26 ReadKey(3)
All times are GMT -4. The time now is 12:38 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy