about output redirection

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • zehrhand
    New Member
    • Nov 2007
    • 4

    about output redirection

    hello!
    I am currently writing my own script and need help on output redirection.as u know 'ls -al > myfile' would write the files in the current directory into the file called myfile.i know about opening a file and writing with fputc but have no idea about how to prevent the command from writing the output to terminal and get the output data to write to file..i hope i could tell my problem and someone could have an idea.
  • numberwhun
    Recognized Expert Moderator Specialist
    • May 2007
    • 3467

    #2
    Originally posted by zehrhand
    hello!
    I am currently writing my own script and need help on output redirection.as u know 'ls -al > myfile' would write the files in the current directory into the file called myfile.i know about opening a file and writing with fputc but have no idea about how to prevent the command from writing the output to terminal and get the output data to write to file..i hope i could tell my problem and someone could have an idea.
    First, I have deleted your duplicate post. Please do not double post your questions.

    Second, I am not sure that I understand. Are you saying that you want the default output for your Terminal to be a file instead of the screen? If that is the case, how will you know what you are doing? If that is NOT what you want, then you will really have to better explain your question as it is rather confusing.

    Regards,

    Jeff

    Comment

    • zehrhand
      New Member
      • Nov 2007
      • 4

      #3
      sorry about the duplicate post i tried to delete it but couldnt figure out how to do that.
      i am trying to build a shell for my hw so if the user enters such a command "ls -al > myfile.txt" my shell should write the "ls -al" output into the myfile.txt instead writing to shell page..(just the same what bash shell does)

      Comment

      • zehrhand
        New Member
        • Nov 2007
        • 4

        #4
        prevent the command from writing the output to terminal .
        i am talking about the output of "ls -al "here..not all of the outputs we get from the shell

        Comment

        • pbmods
          Recognized Expert Expert
          • Apr 2007
          • 5821

          #5
          Heya, zehrhand.

          `ls -al > myfile.txt` doesn't do what you're expecting it to do?

          Comment

          • zehrhand
            New Member
            • Nov 2007
            • 4

            #6
            yea but i want to write a function which does that job.i dont want to use built-in functions..if my shell uses system functions for all jobs,then whats the point of writing a shell?

            Comment

            Working...