CS 113 -- Miscellaneous FAQ Q. What do I do about programs with long output? I can't see it all on the screen at one time and it goes by to fast to read. A. Unix allows for redirection of input and output and for pipes. Theses two features provide several solutions to this problem, none of which require that you change your programs. Redirection of Output: ===================== Anything written to standard output (that is where printf writes) can be sent instead to a file. There are three related ways to do this: myprog > myoutput.file myprog >> myoutput.file myprog >! myoutput.file where myprog is the name of the program and myoutput.file is the name of the file where you want to store the output. The first makes a new file. If myoutput.file already exists, nothing happens to it. The second adds to the end of myoutput.file; in this case, the file must already exist. The third overwrites myoutput.file; whatever was in the file before is gone forever. Note: in any of these cases, you will not see any standard output on the screen. When the program is done running, your prompt will reappear. (But you might see some error messages, which are handled differently.) Redirection of Input: ==================== You can also use redirection to store the commands you need to give your program in a file, so that you don't have to type them every time you test the program. This time the syntax is myprog < myinput.file This is precisely how your homework log files are generated. Redirection of Input and Output: =============================== You can combine these into one command, for example myprog < myinput.file > myoutput.file Pipes: ===== Instead of sending the output of your program to a file, you can send it to another program. This is called a pipe (imagine a pipe taking the ouput of one function and hooking it up to the input of another function). The syntax is firstprogram | secondprogram Two possible second programs which may interest you are more and tee. more will display its input one page at a time. Thus myprogram | more will display the output of your program one page at a time. tee sends its input both to the screen and to a file. Use myprogram | tee myoutput.file or myprogram | tee -a myoutput.file to send the output of your program to both the screen and to a file. (In the second example, the -a tells tee that myoutput.file is to be appended.) Q. I was wondering if you knew how to automatically forward email messages to a different address (i.e., if I receive mail at my CSA account, I'd like it automatically forwarded to my ACS account). This allows users to only check one address for e-mail. A. On a unix system the way to do this is to create a file in your home directory call .forward each line of this file should contain an email address to which you want the mail forwarded. If you also want a copy to stay in your csa account, put that address in the .forward file as well. Otherwise, the mail will be forwarded to acs and no trace of it will remain on csa.