need help - C program on redirection

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • KiranJyothi
    New Member
    • Apr 2007
    • 45

    need help - C program on redirection

    Hello All,

    In whotofile.c, we can see that we are redirecting the output of who to a file.


    In pipe.c, we see that we are redirecting the o/p of first command as the input to the next command.

    I want to write a program without using dup or dup2 to redirect the output of who as the input of sort.

    Can anyone please help me with this?

    Thanks in advance.

    -KiranJyothi
    Last edited by sicarie; Mar 17 '08, 12:48 PM. Reason: if you use code tags and your code disappears, its too much code for a person to look through for quick help on a forum. code removed
  • gpraghuram
    Recognized Expert Top Contributor
    • Mar 2007
    • 1275

    #2
    I havent seen the code fully----
    I am answering for below part
    I want to write a program without using dup or dup2 to redirect the output of who as the input of sort.

    Logic for this is
    1)First open a file using open system call
    2)As it is opened successfully what you do is dup the file descriptor
    3)Then use dup2 to swap the file descriptor to the stdout's descriptor
    4)Now whatever you write to stdout will be part of the file
    5)As you are done again call dup2 to swap the descriptors properly
    6)close the file descriptor

    Raghuram

    Comment

    Working...