digitalmars.D.learn - Read from stdin without blocking
- Benjamin Thaut (9/9) Jan 13 2015 I want to read all input from stdin without blocking. That means
- Adam D. Ruppe (15/15) Jan 13 2015 The operating system does line buffering, so you'll need to turn
I want to read all input from stdin without blocking. That means I simply want to read the remaining input from stdin. All ways I tried so far always end up in me waiting for the user to enter additional input, which is not what I want. I tried around a lot with D's files / streams but couldn't find any way to do that. Any help is appreciated. Kind Regards Benjamin Thaut
Jan 13 2015
The operating system does line buffering, so you'll need to turn that off. The function is tcssetattr() on Posix and SetConsoleMode on Windows. My terminal.d does this in struct ctors and dtors: https://github.com/adamdruppe/arsd/blob/master/terminal.d example usage: http://arsdnet.net/dcode/book/chapter_12/07/input.d The RealTimeConsoleInput struct turns off buffering and has functions like getch() and kbhit() to fetch individual characters from it. That's not quite the same as getting everything that's available, but might be useful to you. Most efficient way I think though is to turn off buffering with the OS calls, then you can set stdin to be nonblocking and read chunks off it with ordinary read() or ReadFile calls.
Jan 13 2015