Command Line Redirection




Document: Software Engineering 1: Lab Exercises

next Plotting a Graph
up Hints
gif Functional Decomposition

Command Line Redirection

  If you want to plot a graph of the trajectory calculated by your program, you will need to capture the program output in a file, rather than having it simply displayed on the screen.

Perhaps the simplest way of arranging for a program to route its output to a file (or, indeed, to take its input from a file), is to use so-called command line redirection.

Suppose your program is in a file called foobar.c. After successful compilation, you will have a executable file called foobar.exe. Normally you would execute this simply by giving the name foobar as a command. However, if you want to use command line redirection, you would give a command somewhat like this instead:

        foobar   >out.txt   <in.txt

The < serves as the "input redirection" character in an MS-DOS command line. The effect is that the input for foobar will no longer be taken from the keyboard, but from this file instead. Similarly, the > character in an MS-DOS command provides for output redirection, to direct output to a file instead of the screen.

With any given command invocation you can choose to use no redirection at all (as we have been doing up to now), or to use input redirection only, or output redirection only, or both together.




Document: Software Engineering 1: Lab Exercises

next Plotting a Graph
up Hints
gif Functional Decomposition



McMullin@eeng.dcu.ie
Tue Apr 30 14:15:37 GMT 1996