Sponsored Content
Top Forums Programming Simple capturing of keyboard input without interruption Post 303014186 by jim mcnamara on Tuesday 6th of March 2018 03:40:41 PM
Old 03-06-2018
Overview:
I'm not going to figure out all of the above wall of code. This example is how MS windows and X work. A simple, fairly stupid, event (message) pump that does nothing but read stdin, then send it off to a pipe. The little one I call "tiny" your code wall is "big" and it needs to dup() stdin on startup.

What you will do is to steal a tiny bit of windowing architecture - as in a message pump:
interpose a tiny program that loops and reads each character from stdin and then sends everything it gets from stdin to a pipe -except the <return> key. It exits or whatever you need on the return key.

Start the tiny program, have it fork your large program as a child that reads input from a pipe. Big's code can live in the same physical code that tiny lives in. Call fork() on the "big" entry point.

Tiny reads everything and simply passes it on, except in your case tiny exits when the ASCII 13 character (\n) is read. Tiny has almost zero smarts, just calls signal(), read(), wait() and pipe().

If tiny wants to quit: signal big, call wait() on big, then exit().
If big wants to quit: signal tiny, then exit() Tiny's signal handler gets the signal and exits.

If you really get stuck, post your attempt. If executable code lines in the tiny program code exceeds circa 50 lines or so your logic is probably too complex. Add bells and whistles after it works.
This User Gave Thanks to jim mcnamara For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

suppressing keyboard input

Setup Info: This User Id and Password mention below are being used with the ISQL command to connect to a sybase database so they are likely to not be the same as those that were signed on from the session. Situation: Using a korn shell, the shell prompts for a User Id and Password. During the... (1 Reply)
Discussion started by: anthreedhr
1 Replies

2. Programming

Detecting Keyboard Input without return

Hi, I need a way to detect the up and down arrow key inputs for my program. I do not want to wait for the return key to be entered(so that rules out getch() and family). Also I need to process several of these inputs in parallel, by servicing each request with a thread. Is that possible? ... (4 Replies)
Discussion started by: ravneetd
4 Replies

3. Programming

Keyboard Input

Does anyone know how do you determine the user idle time of STDIN in order to log the user out for being idle too long. I would like to write a c program to do this but I it is not clear upon how to determine idle time from keyboard input. I have found that the "who.c" source file uses the last... (4 Replies)
Discussion started by: cpaquette
4 Replies

4. UNIX for Dummies Questions & Answers

Capturing Input Parameters on Shell Script

i have this basic line of code that doesn't work. i simply want to get the input parameter strings but when the script is run it appears that the first parameter is assigning the value to the second parameter. #!/bin/sh pdir=`pwd` p1=$1 p2=$2 echo "directory: $pdir\n" echo "parameter... (2 Replies)
Discussion started by: wtolentino
2 Replies

5. Shell Programming and Scripting

Keyboard input question

How would I change up a script that currently has something like: bash script echo what's 1 2 3 4? then using read 1 2 3 4 I type 1 2 3 4. so in the script i can do stuff like echo $1 $2 $3 $4 and such... i was just doing echo "1 2 3 4"|bash script But was wondering how could I... (5 Replies)
Discussion started by: biopulse
5 Replies

6. Shell Programming and Scripting

Capturing script output and input to log

Hi Is there a way that I can capture a shell script (both output and input) to a log file where I can analyze it? Thanks (6 Replies)
Discussion started by: nimo
6 Replies

7. Shell Programming and Scripting

sed execution with input from keyboard

> sed '' Hello hi Hello output How hi output ^D How > sed should take each line as input, process and output the result. In the above scenario the input is passed from keyboard and the output of 'Hello' as you can see is displayed on the screen after 'hi' is passed as input but not as... (1 Reply)
Discussion started by: loggedin.ksh
1 Replies

8. Shell Programming and Scripting

Capturing multiple values from user input

Hello, I need to capture multiple values from user input and do not know how to do it. I'm writing a script to delete old files, but want to give the option to keep some by asking the user. This is what my output looks like... Old files to be deleted... 1 file1 2 file2 Then this bit of... (3 Replies)
Discussion started by: jrymer
3 Replies

9. Shell Programming and Scripting

How to get input from keyboard with watch?

Hello, i`m trying to create an network monitoring script and i dont know how to make affect that script by pressing an key from keyboard and that script runs not in while or for or any other loop, but with bash command watch for example: i have created an file (for example check) with content... (0 Replies)
Discussion started by: bacarrdy
0 Replies

10. Shell Programming and Scripting

Read input from Keyboard, do not proceed if no input

Hi, I am working on a script, which requests users to enter input. Ex: read -p "Please enter your email id:" email I don't want users skipping this entry, this has to be mandatory.I dont want to proceed without input. I can do a check if variable $email is empty and proceed if not.But, i... (7 Replies)
Discussion started by: aravindadla
7 Replies
Debian::Rules(3pm)					User Contributed Perl Documentation					Debian::Rules(3pm)

NAME
Debian::Rules - handy manipulation of debian/rules SYNOPSIS
my $r = Debian::Rules->new('debian/rules'); my $r = Debian::Rules->new( { filename => 'debian/rules' } ); $r->is_dh7tiny && print "Using the latest and greatest "; $r->is_quiltified && print "quilt rules the rules "; # file contents changed externally $r->parse; $r->add_quilt; $r->drop_quilt; $r->write; # or undef($r); DESCRIPTION
Some times, one needs to know whether debian/rules uses the debhelper(1) 7 tiny variant, or whether it is integrated with quilt(1). Debian::Rules provides facilities to check this, as well as adding/removing quilt integration. Modified contents are written to file either vie the "write" method, or when the object reference goes out of scope (via DESTROY). CONSTRUCTOR
"new" is the standard Class::Accessor constructor, with the exception that if only one, non-reference argument is provided, it is treated as a value for the filename field. If a file name is given, the constructor calls "read" to read the file contents into memory. One of filename or lines is mandatory. FIELDS
filename Contains the file name of the rules file. lines Reference to an array pointing to the rules file. Initialized by "new". METHODS
parse Parses the rules file and stores its findings for later use. Called automatically by is_dh7tiny and is_quiltified. The result of the parsing is cached and subsequent calls to "is_XXX" use the cache. To force cache refresh (for eample if the contents of the file have been changed), call "parse" again. is_dh7tiny Returns true if the contents of the rules file seem to use the so called tiny variant offerred by debhelper 7. Tiny rules are detected by the presense of the following two lines: %: dh $@ (any options on the "dh" command line ignored). is_quiltified Returns true if the contents of the rules file indicate that quilt(1) is used. Various styles of "quilt" integration are detected: dh --with=quilt quilt.make with "$(QUILT_STAMPFN)" and "unpatch" targets. add_quilt Integrates quilt(1) into the rules. For debhelper 7 tiny rules (as determined by "is_dh7tiny") "--with=quilt" is added to every "dh" invocation. For the more traditional variant, quilt is integrated vua quilt.make and its "$(QUILT_STAMPFN)" and "unpatch" targets. drop_quilt Removes quilt(1) integration. Both debhelper 7 tiny style ("dh --with=quilt") and traditional ("$(QUILT_STAMPFN)" and "unpatch") approaches are detected and removed. read [filename] Replaces the current rules content with the content of filename. If filename is not given, uses the value of the "filename" member. write [filename] Writes the in-memory contents filename. If not given, uses the value of the "filename" member. If "lines" points to an empty array, the file is removed. COPYRIGHT &; LICENSE Copyright (C) 2009, 2010 Damyan Ivanov <dmn@debian.org> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation. 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. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. perl v5.14.2 2012-01-15 Debian::Rules(3pm)
All times are GMT -4. The time now is 06:04 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy