Relative Content

Tag Archive for inputtclstdin

TCL: get 1 or 2 characters from user, discard other input

I’m trying to write a TCL script that reads from stdin channel 1 or 2 characters from user, discarding anything other from user input without reading it.
Malicious user can create a very long string to try to overflow the buffer, that’s why I want to read maximum 2 characters.
I understand, to do it, something like read $chan 2 and chan pending input $chan can be used together, but I cannot figure out how to do it right.