What is the Windows (Win32) command-line equivalent of the Unix pipeline:
myprog myarg | cat >out.dat
Please note that I want to have a pipe, to test that myprog can write successfully to a pipe, so please don't simplify it to this:
myprog myarg >out.dat
I'd guess something like
myprog myarg | copy /b con out.dat
would work, but I don't have a Windows machine to check.
Please note that the generated data is binary, it contains all possible bytes values 0 .. 255, and all of them must be preserved intact, without any transformation.
Since Windows doesn't come with such a program, here's a quick one in C.
#include <stdio.h>
#include <io.h>
#include <fcntl.h>
int main()
{
char buffer[16384];
int count;
_setmode(_fileno(stdin), _O_BINARY);
_setmode(_fileno(stdout), _O_BINARY);
while ((count = fread(buffer, 1, sizeof(buffer), stdin)) != 0)
fwrite(buffer, 1, count, stdout);
return 0;
}
You can easily modify it to write to a file of your choosing instead of stdout
.
There's nothing built into Windows equivalent to the way you're using cat
in the example given. The command you suggest (copy /b con
) certainly won't work, because con
is the console device, not the standard input.
You could try the GNU utilities for Win32, which includes a port of cat
. Otherwise you may need to write your own code, which would of course be simple enough.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With