If you compile programs normally for win32, you will not be able to use redirection on binary files:

myprogram < c:\command.com > c:\command.tmp

Because of various issues with Windows (translation of carriage returns and EOF characters), the data will almost always be corrupted and truncated.

To fix this, add the following lines at the beginning of your program:

#ifdef WIN32
  _setmode (_fileno (stdout), O_BINARY);
  _setmode (_fileno (stdin), O_BINARY);
#endif

In order to use these functions and constants, you'll need to include:

   #include <io.h>
   #include <fcntl.h>

That's it! Redirection in my programs worked great after doing this.

Back to TIWICHLOTIETWT


Windows, binary, redirection, emacs, NT, WIN32, Win98, 98, Windows NT, Windows 98, Windows 95, Win95, Win32, text, binary, O_BINARY, O_TEXT, less-than, greater-than, DOS, stdin, stdout, set mode, hexl, Visual Studio, Visual C++, MFC