Both Ways at Once
Redirection of input and output can be used together; the input for a program can come from a file via redirection, at the same time its output can be redirected to a file. Such a program is called a filter. The following command demonstrates this process.
C>UTIL < NEWPOEM.TXT > POETRY.TXT
In this case our program receives the redirected input from the file NEWPOEM.TXT and instead of sending the output to the screen it would redirect it to the file POETRY.TXT.
Similarly to send the contents of the file NEWPOEM.TXT to the printer we can use the following command:
C>UTIL < NEWPOEM.TXT > PRN
While using such multiple redirections don’t try to send output to the same file from which you are receiving input. This is because
the output file is erased before it’s written to. So by the time we manage to receive the input from a file it is already erased.
Redirection can be a powerful tool for developing utility programs to examine or alter data in files. Thus, redirection is used to establish a relationship between a program and a file. Another OS operator can be used to relate two programs directly, so that the output of one is fed directly into another, with no files involved. This is called ‘piping’, and is done using the operator ‘|’, called pipe. We won’t pursue this topic, but you can read about it in the OS help/manual.
Redirection can be a powerful tool for developing utility programs to examine or alter data in files. Thus, redirection is used to establish a relationship between a program and a file. Another OS operator can be used to relate two programs directly, so that the output of one is fed directly into another, with no files involved. This is called ‘piping’, and is done using the operator ‘|’, called pipe. We won’t pursue this topic, but you can read about it in the OS help/manual.
No comments:
Post a Comment