IO Redirection
Redirection in Windows from the command prompt is quite
easy using pipes (<, >) at run time. To pipe a file into the standard input use
"<" followed by the file name. To pipe the standard output to a file use ">"
followed by the file name.
To make this happen with the simplest commands we need to
have the input file in the same folder as the executable file and have the
command prompt at the same location. We will use Lab 5 as our example.
- Our executable program is in the Debug folder (if
using an Eclipse workspace configured as in the labs). We will create two
files in this folder using Notepad.
-
The first we saveAs "in.txt" for lack of a better name.
This file holds the
contents of our input.
324
23
4657
0
3
5
45
8
3
56
-
The second we will saveAs "cmd.bat" and it will contain only this line
cmd.exe
To ensure that Notepad does not add the file extension ".txt" when we use
saveAs place the file name in double quotes.

-
Notice the Address of the Debug folder for our Lab 5 project. Also notice
that the file extension determines the application that will be used to open
the file. Here we have an executable, a batch file and a text file.
Double click on the cmd.bat file to open the command prompt window in
the current folder:
Type in the name of the executable followed by the appropriate command
line arguments. For lack of a better name we will pipe the output to a file
named "out.txt"
This IO redirection results in the out.txt file creation.