pipe to file and still display to screen?

This is a discussion on pipe to file and still display to screen? within the Tech Board forums, part of the Community Boards category; Hello, I'm trying to find a way to save my screen output to file and yet still see it display ...

  1. #1
    Registered User
    Join Date
    Mar 2005
    Posts
    8

    pipe to file and still display to screen?

    Hello,

    I'm trying to find a way to save my screen output to file and yet still see it display on the terminal. i thought about piping it into a file, but then i won't be able to see it on the screen as well.. anyone have any work-arounds?

    thanks.

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    I believe *nix has tee, otherwise just output both to a file and the stdout.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Registered User
    Join Date
    Mar 2005
    Posts
    8
    i want to be able to run my program, output to a file, and still see the output on the screen as well. i have one of those run away loops and i need to see the state that it occurs. its a client-server program so and the server port is also displayed to he screen. without the port, it can't connect from the client.

  4. #4
    Registered User Kybo_Ren's Avatar
    Join Date
    Sep 2004
    Posts
    136
    Allow a command-line parameter that's the file name to output to. If one is given, also output to that.

    Heck, you could even allow multiple file outputs with a simple loop.

  5. #5
    PC Fixer-Upper Waldo2k2's Avatar
    Join Date
    May 2002
    Posts
    2,001
    some shells in *nix also deem the >> as meaning to file and stdout.
    PHP and XML
    Let's talk about SAX

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,832
    > some shells in *nix also deem the >> as meaning to file and stdout.
    Which ones, so I know to avoid them
    In all the shells I know about, >> means append to an existing file.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  7. #7
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    pipe to a file and "tail -f" the file?

  8. #8
    Registered User Scribbler's Avatar
    Join Date
    Sep 2004
    Location
    Aurora CO
    Posts
    266
    As somebody mentioned already, tee should work for you.

    I believe tee copies all output to stdout to a designated file. So ls -l | tee savefile will display your directory listing in long format to screen, and also save it all to savefile.

  9. #9
    PC Fixer-Upper Waldo2k2's Avatar
    Join Date
    May 2002
    Posts
    2,001
    >>Which ones, so I know to avoid them

    I'll have to ask my unix teacher what shell he was using when he showed us that...I have a feeling it wasn't a popular one though from what you say...might have been a homegrown one just for teaching purposes...
    PHP and XML
    Let's talk about SAX

  10. #10
    Registered User
    Join Date
    Mar 2005
    Posts
    36
    Hopefully you misunderstood him. Anyway "tee" is a standard *nix utility which does what you want as described above. It is a simple program to write if you don't have it - you just read characters from stdin, then write them to both stdout and a file whose name you give it on the command line. You could make it a bit more interesting and number the lines you write to the file, maybe also write a start time and end time out to the file to help you find the place you want if you know when the error occurred.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21