Prevent the line discipline from handling control characters

When you send a control character from the terminal, for example if you pressed Ctrl+C, the line discipline will receive the byte representing this control character (which is 0x03 in the case of Ctrl+C).

Now instead of the line discipline sending the byte 0x03 to the program associated with the terminal, it will instead send it the SIGINT signal (or it will do some other action if it is a different control character).

Now is there a way to prevent the line discipline from handling control characters, so what I want is for the program associated with the terminal to receive the actual bytes representing the control characters (0x03 in our case).

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

On linux, you’d use

$ stty intr undef

on the terminal concerned. That sets the interrupt character to nothing (“undef”). To restore you would use

$ stty intr ^c

See man stty for details.

Method 2

different control character […] control characters

I note the plural. You are looking for non-canonical input mode, known before the POSIX standard as raw mode. This is the mode that applications that use GNU Readline, or ZLE, or libedit employ. Their code sets it with the tcgetattr(), cfmakeraw() and tcsetattr() library functions, or similar. These are also the underpinnings of stty raw. (Note the existence of stty sane if you play with this.)

Further reading


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x