Thread: Quick question, print to two files

  1. #1
    Registered User
    Join Date
    Aug 2006

    Quick question, print to two files

    How do you print to both file.stderr and file.stdout.
    What's the command to do that?
    (./something.exe > file.stderr) >& file.stdout

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Oregon, USA
    You're asking this on a C programming forum because...?
    If you understand what you're doing, you're not learning anything.

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Most UNIX and Linux shells (bash, sh, csh, etc) allow you to redirect stderr to a file with 2> (and of course, stdout with >).

    As for using these streams in a C program: well, printing to stdout is quite simple. You can use any number of functions, printf() and putchar() being the easiest. For stderr, just take one of the file output functions and specify stderr as the file.
    fprintf(stderr, "Hello, %s!\n", name);
    fputs(date, stderr);
    putc('!', stderr);
    You can use those functions for stdout, too: just use stdout instead of stderr.

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell

    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ:

    My website:
    Projects: codeform, xuni, atlantis, nort, etc.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    Moved to tech.
    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.

  5. #5

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A quick pointer question
    By samus250 in forum C Programming
    Replies: 7
    Last Post: 07-01-2008, 06:10 PM
  2. Question about ".o" files
    By Jez_Master in forum C++ Programming
    Replies: 1
    Last Post: 04-11-2002, 01:54 AM
  3. * quick question *
    By SavesTheDay in forum C Programming
    Replies: 3
    Last Post: 03-27-2002, 06:58 PM
  4. just a reaaaaaaly quick question plz help
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 03-21-2002, 11:39 AM
  5. Quick question: exit();
    By Cheeze-It in forum C Programming
    Replies: 6
    Last Post: 08-15-2001, 05:46 PM