using system command results in a program

This is a discussion on using system command results in a program within the Windows Programming forums, part of the Platform Specific Boards category; I wan't to know how to copy system command results into a string in my program. For example if I'd ...

  1. #1
    Registered User
    Join Date
    May 2002
    Posts
    51

    using system command results in a program

    I wan't to know how to copy system command results into a string in my program. For example if I'd run "dir" the names of all folders would be stored in my program. In that case I would use system("dir") to run the command. Please don't just post your own "dir" function, since I'm going to use other commands too.

    Since Google has recently begun to "suck", I didn't find anything useful from there.

    thanks in advance
    Last edited by finnepower; 06-03-2005 at 02:27 PM.
    I abuse:

    Borland C++ Builder 6 Enterprise Edition

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,674
    Code:
    system("dir > output.txt");
    Then read in output.txt.

    Or...

    Creating a Child Process with Redirected Input and Output

    gg

  3. #3
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    What you want to do is "pipe" the output from the dir program to your own program. Instead of the programs standard output being the monitor, the programs stdout is sent to a place you specify. I don't recall how to do this on an MS system, so I'll look it up and get back to you.

    edit: Ah yes... that would be how (codeplug - you beat me again!)

    Since Google has recently begun to "suck",
    How so?

  4. #4
    Registered User
    Join Date
    May 2002
    Posts
    51
    Quote Originally Posted by Codeplug
    Code:
    system("dir > output.txt");
    Then read in output.txt.

    Or...

    Creating a Child Process with Redirected Input and Output

    gg
    WHOA!!! I thought that was only possible in Linux. Thanks!

    About google: I don't know if it was google that sucked or me not giving it proper keywords. It's always easier to blame something else
    I abuse:

    Borland C++ Builder 6 Enterprise Edition

  5. #5
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    Yeah - it's tough to find out how to do certain things on Google unless you know the proper term for what it is you want to do.

  6. #6
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    Using system() is rarely if ever a good idea. Read the FAQ for some of the reasons, by no means all of them!

    To log a directory using API routines is very easy. I have a 3 part tutorial starting here which develops a directory logging program using Win32 API functions.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  7. #7
    Registered User
    Join Date
    Jun 2005
    Posts
    4
    Easy ? everybody i know thinks FindNextFile() is a b*tch to use.

    Id use the read in the text file method especially if you want to do it with other programs.

    Actually that tutorial looks good.
    Last edited by Robn; 06-10-2005 at 09:01 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Client-server system with input from separate program
    By robot-ic in forum Networking/Device Communication
    Replies: 3
    Last Post: 01-16-2009, 02:30 PM
  2. Replies: 3
    Last Post: 06-13-2005, 07:28 AM
  3. Date program starts DOS's date
    By jrahhali in forum C++ Programming
    Replies: 1
    Last Post: 11-24-2003, 04:23 PM
  4. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 11:39 AM

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