TYPE command stops on 0x1A, except when piped to MORE?

醉酒当歌 提交于 2019-12-24 08:48:53

问题


If I have a binary file with the following contents:

48 65 6C 6C 6F 1A 48 65 6C 6C 6F

Then when I run the TYPE command on it, it stops reading at the 1A character:

C:\Temp>type file.bin
Hello

However, when I run TYPE again but this time pipe the output to MORE, it produces the following output:

C:\Temp>type file.bin|more
Hello→Hello

C:\Temp>

Which is more representative of the actual contents of the file than the previous command.

What exactly does piping output to MORE do that makes it print out the entire ASCII representation of the file regardless of the presence of a 1A character?


回答1:


type command checks internally where the output will be sent.

If the output stream is the console, the input buffer is checked for the presence of Ctrl-Z (0x1A character) that is handled as EOF.

If the output stream is not the console, then all the characters are handled. This happens not only with pipes, but also redirection.

type file.bin | more
type file.bin > con
type file.bin > file.bin.out

Both redirected and piped type commands will handle all the characters.

This behaviour of 0x1A character is also present in copy command, but in this case it is also documented.



来源:https://stackoverflow.com/questions/39708646/type-command-stops-on-0x1a-except-when-piped-to-more

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!