next up previous contents
Next: Pipes Up: Advanced Topics Previous: TAB Completion   Contents

I/O Redirection

Many programs in UNIX will by default read their input from the user's keyboard and write their output to the terminal. If you write a C program that uses printf and scanf, the program will act this way. This is convenient for debugging, but what about when it comes time to actually test it with your TA's data? In most systems, you would have to recompile your program. With UNIX, you can dynamically redirect the normal input and output streams right on the command line without ever touching the program's code. For example:

[bbadger@demo01] (1)$ prog1 < test-data

runs prog1, taking its input from the file test-data. The output will still be printed on the user's terminal. On the other hand:

[bbadger@demo01] (1)$ prog1 < test-data > results

still reads the input from the file test-data. Also, the output is sent to the file results. For a slight variation, the command:

[bbadger@demo01] (1)$ prog1 < test-data » results

would function the same, except the output is appended to the file results, instead of replacing whatever was there.


next up previous contents
Next: Pipes Up: Advanced Topics Previous: TAB Completion   Contents
Michelle Craft 2008-01-23