Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

TYPE behaving randomly

May
12,846
164
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: 279
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.
 
Are you using the new console? Try restarting TCC in the 'legacy console' mode and see if you can replicate it.
 
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
 
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.
 
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
 
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

Back
Top