kerravon86@yahoo.com.au [hercules-os380]
2018-09-10 06:32:13 UTC
Peppe, some time ago you mentioned that
dup() and dup2() were used to do command
redirection.
Can you elaborate on what is required?
Here's my guess:
When the command processor has received
a command like:
fred > fred.txt
it should call dup() to save a handle (e.g. file
number 17) to normal stdout (file number 1),
then open fred.txt, e.g. file number 25, then
call dup2() to make file number 1 point to file
number 25, then close file number 25, then
run the command, then call dup2() to make
file number 1 a copy of file number 17, then
close file number 17.
Is that the right procedure?
Thanks. Paul.
dup() and dup2() were used to do command
redirection.
Can you elaborate on what is required?
Here's my guess:
When the command processor has received
a command like:
fred > fred.txt
it should call dup() to save a handle (e.g. file
number 17) to normal stdout (file number 1),
then open fred.txt, e.g. file number 25, then
call dup2() to make file number 1 point to file
number 25, then close file number 25, then
run the command, then call dup2() to make
file number 1 a copy of file number 17, then
close file number 17.
Is that the right procedure?
Thanks. Paul.