Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Does Piping Binary Text to the Screen often Horck a Terminal

Imaginary Situation: You’ve used mysqldump to create a backup of a mysql database. This database has columns that are blobs. That means your “text” dump files contains both strings and binary data (binary data stored as strings?)

If you cat this file to the screen

$ cat dump.mysql

you’ll often get unexpected results. The terminal will start beeping, and then the output finishes scrolling by you’ll often have garbage chacters entered on your terminal as through you’d typed them, and sometimes your prompts and anything you type will be garbage characters.

Why does this happen? Put another way, I think I’m looking for an overview of what’s actually happening when you store binary strings into a file, and when you cat those files, and when the results of the cat are reported to the terminal, and any other steps I’m missing.

like image 943
Alan Storm Avatar asked Apr 12 '10 18:04

Alan Storm


2 Answers

When you cat a binary file you can inadvertently send control characters to the terminal.

If a terminal application wants to send a beep for example, it sends the following binary to the terminal: 0x007 (SYS V only).

The same goes for colors, cursor position and others.

like image 162
Byron Whitlock Avatar answered Nov 16 '22 08:11

Byron Whitlock


Start here: http://www.faqs.org/docs/Linux-HOWTO/Keyboard-and-Console-HOWTO.html

In particular, sections 3 (Console generalities) and section 4 (reseting your terminal).

It covers a bit more than you're talking about, but should give you what you need.

like image 21
Daniel Martin Avatar answered Nov 16 '22 07:11

Daniel Martin