473,513 Members | 2,752 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

reading one byte from stdin

I'm trying to read one byte from stdin, without the newline.

If I try something like:
>>import os, sys
os.read(sys.stdin.fileno(),1)
I can input a character, but then I have to press enter, which leaves
a newline character in the stdin buffer and requires two keypresses.
Is there any way to read only one keypress in a simple manner (i.e. no
curses)?

Jul 16 '08 #1
1 4136
Mark McDuff schrieb:
I'm trying to read one byte from stdin, without the newline.

If I try something like:
>>import os, sys
>>os.read(sys.stdin.fileno(),1)

I can input a character, but then I have to press enter, which leaves a
newline character in the stdin buffer and requires two keypresses. Is
there any way to read only one keypress in a simple manner (i.e. no
curses)?
Depending on your OS, yes. Under *nix, you need to set the terminal to
RAW-mode.

This recipe claims to be OS-agnostinc:

http://aspn.activestate.com/ASPN/Coo.../Recipe/134892

Diez
Jul 16 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
6732
by: brucoder | last post by:
Are there runtime settings that can be used to adjust the default 1024 byte stdin buffer limit or a buildtime setting in pyconfig.h? I have a need to pump this up to permit input of a large data...
2
3472
by: Dan | last post by:
Hello. I have recently tried upgrading the MySql connector for my servlet from 2.0.4 to 3.0.9. I have found a minor limitation in 2.0.4 and was hoping that 3.0.9 would fix it. However, now I...
1
3513
by: Jakob Bieling | last post by:
Hi, whenever I try to read input from stdin, the called function (ie. std::cin.read ()) blocks until my buffer is full. But I want to function to return immediately, regardless of having read...
3
10135
by: Fernando Arbeiza | last post by:
Hi: I need some clarification about a code like this: printf("%s", "a string with NO trailing newline"); scanf("%d", &i); Regarding if a fflush() of the standard output is needed or not. I...
2
4277
by: Li Zhang | last post by:
I have a problem with reading byte from a memory stream. Basically I want to resize a image and then store them to sql server. Here is part of the codes. every time I tried to read byte from...
0
2175
by: rci | last post by:
Hi. I want to read several words from stdin (save them in string) and then process this string. The problem is that my code works for the first time but when i finish processing i cannot read a new...
7
6145
by: Markus Mayer | last post by:
Hi folks. I'm somewhat new to *nix programming and just ran into a problem. I have to take user input from the terminal but like to constrain that to some rules given, i.e. "numbers only" or...
2
4938
by: Rudy Gevaert | last post by:
Hi, I have written an perl program that read from stdin: while(<STDIN>) { chomp do_it($_); } Data is fed to it via a pipe:
6
3317
by: Ashit Vora | last post by:
Hi, I had one small query. I 'm coping data from an unsigned short to a char*. code is #include<stdio.h> int main(void){ unsigned short type=0xFE10;
5
705
by: Luis Zarrabeitia | last post by:
I have a problem with this piece of code: ==== import sys for line in sys.stdin: print "You said!", line ==== Namely, it seems that the stdin buffers the input, so there is no reply until ...
0
7257
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7157
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7379
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7098
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7521
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5084
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4745
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
1
798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
455
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.