Notice! This document is currently in Archived status.
The content of this document may be incorrect or out dated.

Redirecting input-output

It is often desirable to route program input and output from files instead of the terminal. A program which uses standard I/O devices (5 & 6), may be used to read data stored in a file called data, rather than the screen. The command is executed using the redirect symbol (<) as shown below:
	 a.out < data
All device 5 read statements are directed to the file data instead of the keyboard. Notice that all device 6 output will default to the terminal screen. The source program and data should be in separate files (data files should neither be compiled nor linked). Similarly, to route the output to a file called outdata, another type of redirect may be used:
	 a.out > outdata
The file outdata will be immediately created if it doesn't exist. If there is such a file, it will be replaced by a new copy of outdata. Again, all read statements on device 5 default to the screen, thus the input has to be supplied interactively.

The disadvantage of this method is that the program will not write to the screen prompting for input; hence the user will not know when input is expected. This is solved by combining the redirect commands as shown:

	 a.out < data > outdata

Last modified: 2007/06/21 12:37:13.654000 GMT-4 by Unknown
Created: 2007/06/21 12:37:13.654000 GMT-4 by brian.r.brinegar.1.



Type in a few keywords describing what information you are looking for in the text box below.

Admin Options: Edit this Document