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.
 

  1. 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.
    1. The first we saveAs  "in.txt" for lack of a better name. This file holds the contents of our input.

    2. 324
      23
      4657
      0
      3
      5
      45
      8
      3
      56
      
    3. 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.
    4. 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.
  2. Double click on the cmd.bat file to open the command prompt window in the current folder:
  3. 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"
  4. This IO redirection results in the out.txt file creation.