TYPE behaving randomly

May 20, 2008
11,400
99
Syracuse, NY, USA
I know I shouldn't be using TYPE on a binary file ... but I am. The attached random32.zip contains 7.rnd, a 32-byte file of randomly chosen bytes. If I "TYPE 7.rnd" many times I am very likely to get different results, some obviously corrupted. That's troublesome.

1586365110748.png


Oddly enough, this randomness occurs even if the command is the first (and only) command in a new TCC.

1586365722059.png


In comparison, CMD's TYPE shows the same thing every time.
 

Attachments

  • random32.zip
    145 bytes · Views: 104
May 20, 2008
11,400
99
Syracuse, NY, USA
I don't really care if I see the same thing as is CMD. But I'd feel comfortable if I saw the same thing (albeit garbage) every time.
 
May 20, 2008
11,400
99
Syracuse, NY, USA
TCC does no formatting whatsoever on its TYPE output. It just reads the file and dumps everything to WriteConsole; the Windows console is responsible for the output.
My experience with WriteConsole is that if you tell it to write N characters from buffer buf many times, you'll get the same thing each time as long as buf contains the same thing each time. I suspect that the problem is in putting stuff into the buffer, and that WriteConsole is reading past the end of what was put there.

WSL's cat, Gnu's cat.exe, CMD, and Powershell all manage to show it the same each time (though different from each other).

1586371829394.png
 

rconn

Administrator
Staff member
May 14, 2008
12,345
150
I could change TCC to use WriteFile (like CMD) instead of WriteConsole. Then you'd have the same useless (and still wrong) output as CMD. And TYPE would be 2x slower. Do you prefer a massive slowdown for the sake of consistent erroneous output?

I honestly don't see why this is an issue or why anyone would care. Pick the app that produces the wrong output most pleasing to you. Or ask Microsoft to fix their APIs.
 
May 20, 2008
11,400
99
Syracuse, NY, USA
It's not that the output is wrong; it's that it's random. When I make sure all 32 characters of that file make it into the buffer, I get this, using the buffers (CHAR then WCHAR) with WriteConsole (A then W). And I get the same thing every time. How does TYPE read the file into the buffer?

1586376426819.png
 

rconn

Administrator
Staff member
May 14, 2008
12,345
150
ReadFile, unless you're using /L or /P.

Make sure you've turned off all Unicode / UTF8 processing, and you're using a Unicode font. And remember that CMD doesn't support Unicode, so unlike TCC it won't convert your random high-bit ASCII characters to UTF16 before displaying them.

And then don't use TYPE, use VIEW. Or even LIST. Anything but TYPE. (End of conversation.)
 
Similar threads
Thread starter Title Forum Replies Date
Joe Caverly Using TYPE with non-English text Support 22
vefatica Garbage from TYPE Support 2
vefatica TYPE resets console tab settings Support 14
Joe Caverly Get a variable type Support 2
Joe Caverly v24 TYPE Re-direction Support 4
vefatica TYPE goes crazy with no-BOM Unicode file Support 7
J Piping ANSI control sequences through 'type' Support 4
nickles How to? Follow a JUNCTION type directory link Support 9
S International characters - TYPE vs %@LINE function Support 5
thedave WAD Unable to type various characters using Windows 8's onscreen keyboard Support 7
vefatica Fixed TYPE http://... incomplete data Support 40
Phileosophos Documentation TPIPE /string type code confusion Support 4
S WAD %_do_errors does not report errors when loop control variable type is not directory entry Support 1
vefatica TYPE beeping? Support 12
Charles Dye TYPE /P behaves strangely with piped/redirected input Support 0
vefatica LIST and TYPE show UTF8 BOM Support 4
vefatica TYPE, Unicode, installer Support 10
Charles Dye Fixed TYPE /X reports FF for all values >= 80h Support 6
M More SafeChars type issues... Support 4
Charles Dye Strange output, here-doc redirection, TYPE, //UnicodeOutput=Yes Support 6
Roedy MIME type for *.btm ? Support 1
S TYPE command issue Support 12
vefatica TYPE /X and Unicode files? Support 0
dcantor LIST /X and TYPE /X give different results Support 20
Juanma Barranquero App Paths of type REG_EXPAND_SZ Support 2
E colorization outside of type Support 7
p.f.moore Documentation tweak for TYPE Support 5
C Nested IF syntax — TCC behaving differently to CMD Support 12
T Fixed Echo randomly activated in script Support 4

Similar threads