system();

This is a discussion on system(); within the C Programming forums, part of the General Programming Boards category; hey everyone i am making a test program, and i was wondering, if i was to call system("dir"); (on windows), ...

  1. #1
    Registered User
    Join Date
    Oct 2004
    Posts
    16

    system();

    hey everyone

    i am making a test program, and i was wondering, if i was to call system("dir"); (on windows), how would i capture the output, and put it in a string, or something to display in my c program.

    thanks

  2. #2
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Well I wouldn't advise using system() but:
    system ("dir >temp.txt") would reidrect the output from dir to a file called temp.txt
    From there you could open the file and parse your little heart aawy

  3. #3
    Registered User
    Join Date
    Oct 2004
    Posts
    16
    thats a good idea.. what would u advise instead of using system?

  4. #4
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    search the board for the reason why you shouldn't use system()

  5. #5
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,163
    A better function to use might be popen(), which would send the output from the dir command directly to your program.
    If you understand what you're doing, you're not learning anything.

  6. #6
    Registered User
    Join Date
    Oct 2004
    Posts
    16
    okay, thanks itsme

    Quote Originally Posted by Thantos
    search the board for the reason why you shouldn't use system()
    ok ill look and see what i can find.

  7. #7
    Registered User
    Join Date
    Oct 2004
    Posts
    16
    hmm, popen is a unix function.. is there a windows equivalent?

  8. #8
    Obsessed with C chrismiceli's Avatar
    Join Date
    Jan 2003
    Posts
    501
    You can look here for some basic technique for running another program, then figure out how to capture the output.
    http://faq.cprogramming.com/cgi-bin/...&id=1043284392
    Help populate a c/c++ help irc channel
    server: irc://irc.efnet.net
    channel: #c

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File System Implementation
    By dodgeviper in forum C Programming
    Replies: 9
    Last Post: 11-16-2007, 12:04 PM
  2. Using system icons
    By @nthony in forum Windows Programming
    Replies: 1
    Last Post: 01-13-2007, 06:56 PM
  3. Linux database system needed
    By BobS0327 in forum Tech Board
    Replies: 7
    Last Post: 06-11-2006, 03:56 PM
  4. BIOS system and memory allocation problem
    By beely in forum Tech Board
    Replies: 9
    Last Post: 11-25-2003, 06:12 AM
  5. Number system base M, print numbers N digits wide...
    By biterman in forum C Programming
    Replies: 12
    Last Post: 11-19-2001, 03:31 AM

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