Command line tool to get binary data as String in Windows like Cat?

1.5k views Asked by At

So I have program that transforms data by piping the string into stdin like so.

cat input.mp3 | myexe

except I want this commandline tool to run on Windows.

type input.mp3 | myexe.exe

and cat and type provide different inputs because of how Windows treat binary files according to the question that referred to me to use cat. So how can I have a more a faithful representation of cat on Windows? Or is there a way I can the input from cat in pure C? Any help would be appreciated.

Update: Here is my code https://github.com/Skylion007/LVDOWin

forked and ported from: https://github.com/m13253/lvdo

I've modified the argument parsing slightly in my own code (only get-opt not get-opt-long), other than that I am using the same command line statements of the readme in the later repo. I would post the code here, but there is a lot a fluf and I don't want overwhelm an already complex answer.

type hello.mp3 | lvdoenc.exe -s 640x480 -q 6 -b8 | x264 --input-res 640x480 --fps 1 --profile high --level 5.1 --tune    stillimage --crf 22 --colormatrix bt709 --me dia --merange 0 -o public.mkv -

is an example of a command I used to encode the file initially. On Linux, I would use cat.

1

There are 1 answers

8
chqrlie On BEST ANSWER

You can just redirect input from the file this way:

myexe < input.mp3

and force stdin to binary mode at the beginning of the main function in myexe this way:

_setmode(_fileno(stdin), O_BINARY);

You may need to add or remove underscores depending on your tools version.

The text mode versus binary mode is a Windows oddity inherited from the dark ages of microcomputing. It goes back all the way to the 1970s, from a popular pre-MSDOS operating system called CP/M from which is was copied. Unix and all its variants never had this and Apple ditched its non-standard end of line scheme a long time ago. You are unlikely to run you code on old mainframes which had their own weird notion on line based text files.