I'm implementing a shell, and in my shell i have to be able to process '>' '<' '>>' '|'.
I got most of it working, but when the user wants to input in the command line something like:
SHELL$ sort < input > output
im not getting the exact result.
What I get is sort sending the output to STDOUT, and then sort reading from STDIN and sending the output to "output"
I know i have to redirect the input of sort using
dup2(fd, STDIN_FILENO)
fd being the file descriptor of the input file.
The part im curious about is how can i redirect the output of sort, instead of sending the output to STDOUT, sending it to w.e '>' is pointing to, which in my example is output
So the command sort reads input: " sort < input " and this: " > output " will eventually send the output of sort to "output".
Thanks in advance!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…