Running 'cat' on a file opens the print dialog?

2

On a whim today, I ran the 'cat' command on a VirtualBox virtual disk image (VDI) file. As expected, a variety of gibberish was output to the stdout on the console. However about 15 seconds into running the command, the print dialog opened! It displayed a page with just more machine code, ready to print. When I closed the dialog, the file continued on printing as usual.

I'm really mystified by this. I'm running macOS Sierra 10.12.6. Does anyone have any ideas how this kind of behavior can even happen?

Ben

Posted 2017-11-16T13:59:17.227

Reputation: 23

If you cat a binary file, there is no knowing what terminal escape sequences you will trigger. You should check your terminal configuration to see if any escape sequences invoke a print. – AFH – 2017-11-16T14:33:43.747

Answers

2

MacOS's Terminal.app does not appear to do this, but iTerm2 responds to the printer control sequences supported by xterm.

From the command-line, you can do this using

tput mc0

which prints the contents of the screen, or

tput mc5

which turns the printer on. The latter would be more annoying, so your binary file probably had the string corresponding to mc0:

Escape[i

(the sequence for mc5 has a 5 before the i).

For reference:

    CSI Pm i  Media Copy (MC).
                Ps = 0  -> Print screen (default).
                Ps = 4  -> Turn off printer controller mode.
                Ps = 5  -> Turn on printer controller mode.

Thomas Dickey

Posted 2017-11-16T13:59:17.227

Reputation: 6 891