redirect stdout to a file?

This is a discussion on redirect stdout to a file? within the C Programming forums, part of the General Programming Boards category; I want to redirect stdout to a file. say I did: Code: system("dir /b /s c:\*.txt"); this would display all ...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,220

    redirect stdout to a file?

    I want to redirect stdout to a file.

    say I did:
    Code:
    system("dir /b /s c:\\*.txt");
    this would display all the text files on drive C in plain format (one line per file and no details /b does this). I want to redirect this to a file, so my program can search through the txt files for the one it needs.

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Lookup freopen();

    Its part of <stdio.h>

    Though for that task you would do better to lookup findfirst() and findnext() to get the files. The method you are suggesting is very slow and cumbersome...

  3. #3
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,220
    Will do, cheers.

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,484
    *shrug*
    system("dir /b /s c:\\*.txt > wibble.lst");

  5. #5
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Originally posted by Salem
    *shrug*
    system("dir /b /s c:\\*.txt > wibble.lst");
    LOL....oh yeah

    :: hits head ::

  6. #6
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,220
    lol even better

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File transfer- the file sometimes not full transferred
    By shu_fei86 in forum C# Programming
    Replies: 13
    Last Post: 03-13-2009, 12:44 PM
  2. Replies: 3
    Last Post: 03-04-2005, 01:46 PM
  3. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 09:46 AM
  4. Making a LIB file from a DEF file for a DLL
    By JMPACS in forum C++ Programming
    Replies: 0
    Last Post: 08-02-2003, 08:19 PM
  5. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM

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