For our school assignment, we have to implement input/output redirection. I managed to get the input and output redirection work, but I am facing an issue with append redirection.
I am using testfile.txt:
test line 1 test line 2
When the user types ls >> testfile.txt, I expect the output from ls to be added to the testfile. At this moment, the test lines get replaced by the output of the ls program.
The rights that I am using to open the files are the following:
file = open(redirect.getNewFile().c_str(), O_WRONLY | O_TRUNC, S_IRWXU);
Does anyone have an idea where it goes wrong?
Thanks in forward.
Advertisement
Answer
Replaced O_TRUNC with O_APPEND.