Quick question, print to two files

This is a discussion on Quick question, print to two files within the Tech Board forums, part of the Community Boards category; How do you print to both file.stderr and file.stdout. What's the command to do that? Code: (./something.exe > file.stderr) >& ...

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    64

    Quick question, print to two files

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

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,163
    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
    Location
    Canada
    Posts
    8,046
    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.
    Code:
    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.
    dwk

    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: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,532
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129

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, 05:58 PM
  4. just a reaaaaaaly quick question plz help
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 03-21-2002, 10:39 AM
  5. Quick question: exit();
    By Cheeze-It in forum C Programming
    Replies: 6
    Last Post: 08-15-2001, 05:46 PM

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