Originally Posted by
khdani
that's a specific question how do i implement '>'
for example "ls -l >out.txt"
The problem is, none of us really have time to write up the several hundred word response that would completely describe how to do that.
Here's some pseudocode, but I'm not going to fill in all the blanks
Code:
fd = open("out.txt")
if fork() == parent:
close(fd)
wait for the child
else:
close(1)
dup(fd)
exec("/bin/ls")
In other words, the shell opens the output file. Then it forks itself to create a child. The child closes its stdout descriptor, and calls dup() to replace that with the fd of the open file. Then it executes the ls program. The parent, meanwhile, closes the fd (since it doesn't need it) and waits for the child to finish running.
If you want more details, I'll trade you -- provide some code.