On most systems, you can redirect standard input / output / error to other file descriptors or locations.
For example (on Unix):
./appname > output
Redirects stdout from appname to a file called output.
./appname 2> errors > output
Redirect stdout to a file named output and all errors from stderr to the file with errors.
On Unix systems, you can also open the program for the file descriptor and point it to stdin , for example:
echo "input" > input cat input | ./appname
This will lead to reading the program from the channel for stdin .
Here's how to unix various utilities together on unix to create one larger tool.
find . -type f | ./appname | grep -iv "search"
This will run the find and print its output and pass it to. / appname, then the appname output will be sent to the grep input, which then searches for the word βsearchβ, displaying only the results that match.
It allows many small utilities to have a very powerful effect.
Think of > , < and | like plumbing.
> looks like a sink leak, it receives data and stores it where you want to place it. When the shell encounters > , it will open the file.
> file
When the shell sees above, there will be an open file using a standard system call, and remember this file descriptor. In the above case, since there is no input, it will create an empty file and allow you to enter more commands.
banner Hello
This command writes Hello in truly capital letters to the console and causes it to scroll (I use Unix here, as this is what I know best). The output is simply written to the standard version. Using the "receiver" ( > ), we can control where the output goes, therefore
banner Hello > bannerout
will redirect all the data from the standard banner output to the file descriptor that the shell opened and thus will be written to a file called bannerout .
Pipes work similarly > in that they help control the flow where the data goes. Pipes, however, cannot write to files and can only be used to transfer data from one point to another.
For example, here water flows through several substations and waste treatment:
pump --from lake | treatment --cleanse-water | pump | reservoir | pump > glass
Water flows from the lake, through a pipe to the water treatment plant, from the plant back to the pump, which moves it to the tank, then it is pumped again into the municipal water pipes and through your sink into your glass.
Note that the pipes simply connect all the outlets together, eventually they end in your glass.
The same thing happens with commands and their processing in a shell on Linux. He also follows the path to achieving the end result.
Now there is one last thing that I have not talked about in previous instructions, that is, the input symbol < . What it does is read from a file and displays it on stdin for programs.
cat < bannerout
It will simply print what has been stored in the bandage. This can be used if you have a file that you want to process, but do not want to add cat <file> due to the unwillingness to run an additional command in the chain.
So try the following:
echo "Hello" > bannerinput banner < bannerinput
First, the string "Hello" will be placed in the bannerinput file, and then when your launch banner is read from the bannerinput file.
Hope this helps you understand how redirection and copying work on Unix (some, if not most, will apply to Windows as well).