01-29-2009
Number of bytes in terminal input queue w/o blocking and consuming?
Hello, everyone.
Could someone, please, tell me how to get the number of bytes in the terminal input queue without blocking and without consuming these bytes? I guess it could be called the peek functionality.
I've looked at termio tcgetattr() and tcsetattr() functions but could not find exactly what I need. I know I can poll() on stdin. But I don't want to read after poll() returns. I just want to see how many characters, if any, can be read without blocking from stdin - terminal in my case.
Thanks for any hints.
Lucy.
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi,
I have a file that has 300 records with a load of fields. two of them are:
field_1 has between 8-9 bytes i.e. 012345678, 0123456789
field_2 has 10 bytes i.e. 01234567890
I want to be able to echo out the total of each of these fields i.e.
200 (have 8 - 9 bytes)
100 (have 10 bytes)... (3 Replies)
Discussion started by: Pablo_beezo
3 Replies
2. UNIX for Dummies Questions & Answers
Im using the vmstat command to display the CPU run queue, but i want to put that into a program so is there a way to just display the number under the r?
Thanks, (1 Reply)
Discussion started by: RAFC_99
1 Replies
3. Shell Programming and Scripting
Hi,
i have following line in my code.
eport.pl < $4 | dos2ux | head -2000 | paste -sd\| - | awk -v S="$1" '
Issue is, i get a message saying "awk:input line | found /file/path cannot be longer than 3000 bytes."
"source line number is 3"
Can someone help me with this please? (4 Replies)
Discussion started by: usustarr
4 Replies
4. AIX
Hi,
Currently we are experiencing qdaemon died, hourly.
We have more than 10,000 print queue on AIX 5.3.
Would this cause the qdaemon to die?
What is the maximum number of print queue on AIX 5.3?
Thank you in advance. (0 Replies)
Discussion started by: raybakh
0 Replies
5. Shell Programming and Scripting
1) I need a shell code to count the number of files ( without directories or sub-directories ) in a directory given as arguments I tried this code but it didn't work , maybe I tried the wrong one:
numOfFiles=`find $1 -type f -maxdepth 1 | wc -l`
I found it in another thread in this site..
... (17 Replies)
Discussion started by: jack1985
17 Replies
6. Shell Programming and Scripting
Guys,
I want to get the high CPU utilization from top.
I am using below code :
top -d2 >> /home/dba_monitoring/host_top_output.txt
echo "Script started `date`" > $runlog
usage=`grep "^ *$1" /home/dba_monitoring/host_top_output.txt | awk '{print $12}' | sed 's/%//'`
And getting below... (7 Replies)
Discussion started by: wahab
7 Replies
7. Programming
Hi,
I am using the libxml2 sax parser to parse a in memory xml string along with validating it against a schema.
I am using the following code:
xmlSAXHandlerPtr sax_ = new xmlSAXHandler();
sax_->initialized = XML_SAX2_MAGIC;
sax_->startElementNs =... (0 Replies)
Discussion started by: Sam Krishna
0 Replies
8. Shell Programming and Scripting
I am writing a bash script to find out all the files in a directory which are empty. I am running into multiple issues. I will really appreciate if someone can please help me.
#!/bin/bash
DATE=$(date +%m%d%y)
TIME=$(date +%H%M)
DIR="/home/statsetl/input/civil/test"
... (1 Reply)
Discussion started by: monasharma13
1 Replies
9. UNIX for Dummies Questions & Answers
Hello guys. I really hope someone will help me with this one..
So, I have to write this script who:
- creates a file home/student/vmdisk of 10 mb
- formats that file to ext3
- mounts that partition to /mnt/partition
- creates a file /mnt/partition/data. In this file, there will... (1 Reply)
Discussion started by: razolo13
1 Replies
10. Shell Programming and Scripting
hello,
suppose, entered input is of 1-40 bytes, i need it to be converted to 40 bytes exactly.
example: if i have entered my name anywhere between 1-40 i want it to be stored with 40 bytes exactly.
enter your name:
donald duck (this is of 11 bytes)
expected is as below - display 11... (3 Replies)
Discussion started by: shravan.300
3 Replies
read(n) Tcl Built-In Commands read(n)
__________________________________________________________________________________________________________________________________________________
NAME
read - Read from a channel
SYNOPSIS
read ?-nonewline? channelId
read channelId numChars
_________________________________________________________________
DESCRIPTION
In the first form, the read command reads all of the data from channelId up to the end of the file. If the -nonewline switch is specified
then the last character of the file is discarded if it is a newline. In the second form, the extra argument specifies how many characters
to read. Exactly that many characters will be read and returned, unless there are fewer than numChars left in the file; in this case all
the remaining characters are returned. If the channel is configured to use a multi-byte encoding, then the number of characters read may
not be the same as the number of bytes read.
ChannelId must be an identifier for an open channel such as the Tcl standard input channel (stdin), the return value from an invocation of
open or socket, or the result of a channel creation command provided by a Tcl extension. The channel must have been opened for input.
If channelId is in nonblocking mode, the command may not read as many characters as requested: once all available input has been read, the
command will return the data that is available rather than blocking for more input. If the channel is configured to use a multi-byte
encoding, then there may actually be some bytes remaining in the internal buffers that do not form a complete character. These bytes will
not be returned until a complete character is available or end-of-file is reached. The -nonewline switch is ignored if the command returns
before reaching the end of the file.
Read translates end-of-line sequences in the input into newline characters according to the -translation option for the channel. See the
fconfigure manual entry for a discussion on ways in which fconfigure will alter input.
USE WITH SERIAL PORTS
For most applications a channel connected to a serial port should be configured to be nonblocking: fconfigure channelId -blocking 0. Then
read behaves much like described above. Care must be taken when using read on blocking serial ports:
read channelId numChars
In this form read blocks until numChars have been received from the serial port.
read channelId
In this form read blocks until the reception of the end-of-file character, see fconfigure -eofchar. If there no end-of-file charac-
ter has been configured for the channel, then read will block forever.
EXAMPLE
This example code reads a file all at once, and splits it into a list, with each line in the file corresponding to an element in the list:
set fl [open /proc/meminfo]
set data [read $fl]
close $fl
set lines [split $data
]
SEE ALSO
file(n), eof(n), fblocked(n), fconfigure(n), Tcl_StandardChannels(3)
KEYWORDS
blocking, channel, end of line, end of file, nonblocking, read, translation, encoding
Tcl 8.1 read(n)