Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re: Non-blocking reading on STDIN?

by betterworld (Curate)
on Apr 19, 2009 at 10:06 UTC ( #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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://758561]
[Discipulus]: today the teacher covered the stickybit; i vaguely remember i trick with it but.. someone recall it? it was a backdoor like trick

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2017-12-12 19:17 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (335 votes). Check out past polls.