i coded a basic shell in C for executing basic commands it’ll execute commands ls, ls -al , ls -al | more etc.
i want to execute following command in my shell.
like ;
ls -al > a.txt
this will give me a.txt file which contain output of ls -al process.
i found a one solution, it’s changing the command in my shell like [command1] | tee [filename]. in this instance it’ll change ls -al > a.txt to ls -al | tee a.txt. but this process gives the output to file and terminal as well. how to stop printing output in terminal.
or are there are any better solution rather than using tee command.
thanks in advance…
This is the result of my testing things out with dup2
The more subtle point is remembering fflush at the right times 🙂 Otherwise, you’ll get very surprising results.
Also, prefer
filenoinstead of hardcoding1(stdout)2(stderr).Redirecting
stdinwas left as an exercise for the reader