Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Non-blocking reading on STDIN?

by betterworld (Curate)
on Apr 19, 2009 at 10:06 UTC ( [id://758561]=note: print w/replies, xml ) Need Help??


in reply to Non-blocking reading on STDIN?

I want to create a non-blocking read on STDIN, that means I don't have to enter RETRUN, each characters would show up just after I have enter it on the terminal

I think you mean RETURN. Anyway, the two things you mention are not the same. Blocking mode means that read operations blocks until input is available. Input is available if you have typed either a character or a whole line, depending on the terminal settings. This particular setting is known as "canonical mode". You can test it with the "stty" command, but undoubtedly there CPAN modules to leave and enter canonical mode.

Another thing one should be aware about: For terminal applications, usually STDIN has the same file descriptor as STDOUT. This means that if you set the non-blocking flag for STDIN, it will be set for STDOUT, too. This means that if you print a long buffer to the terminal, it might be truncated and print returns EAGAIN. But as nobody checks the error code when printing to a terminal (e.g. curses doesn't seem to do so), the terminal will at some point display unexpected contents.

Replies are listed 'Best First'.
Re^2: Non-blocking reading on STDIN?
by woosley (Beadle) on Apr 19, 2009 at 14:08 UTC
    thanks, betterworld!
    It is related to the setting of the tty. After running command "stty -icanon", it worked out.

    thanks again

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://758561]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (4)
As of 2024-03-29 07:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found