i am making a command line interpreter for an os course. the preoblem statement says that i have to log the output of every command i type in this interpreter along with the usual display in the stdout.

how do i do this?
i have used dup2 to redirect the output to the log file, but then i cannot get the output on the screen.

also i dont want to execute the command twice so that i can output to the stdout once and next time to the file. this is because outputs of some commands(eg. ps) do not remain same..

PLZ help as quickly as possible..

Assuming you need to do it all manually, how about redirecting output to a temporary file? Then you can echo the temporary file to the screen as well as append it to your log file.

Assuming you need to do it all manually, how about redirecting output to a temporary file? Then you can echo the temporary file to the screen as well as append it to your log file.

yes..thats a good idea...thankss a lot...if you get anything better plz let me know.