Thread: retrieve output from system()

  1. #1
    mysterious mongoose
    Join Date
    Apr 2005
    Posts
    18

    retrieve output from system()

    im working on a program that helps manage a network, well sort of anyway.
    The point is that in command prompt, the command, net view, gives you a list of the computer names that are currently on the network.
    What i need to be able to do is hav the program save this list into a variable, or even better, an array.
    Is there a C++ function that returns this list, or, if not, how can i store the output of that system() statement in a variable?

  2. #2
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    You can use the WNetOpenEnum/WNetEnumResource/WNetCloseEnum functions to enumerate all resources on a network.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  3. #3
    ^ Read Backwards^
    Join Date
    Sep 2005
    Location
    Earth
    Posts
    282
    Code:
    cout << system("command");
    Is valid. So is any ostream. You can connect to a temporary file, dump everything from the system() command into the temp file then read and parse the file for data.

  4. #4
    mysterious mongoose
    Join Date
    Apr 2005
    Posts
    18
    Enahs, that actually is not valid, because the return value of a system() command isn't the output, but is either 0 if it worked, or i cant remember what, if it doesnt.
    So this only puts a 0 in the temporary file.
    and envoigt, care to elaborate?

  5. #5
    mysterious mongoose
    Join Date
    Apr 2005
    Posts
    18
    Anyone have any ideas?

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    You could try popen()

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting System Output into C
    By vasillalov in forum Linux Programming
    Replies: 2
    Last Post: 09-25-2007, 04:54 PM
  2. Connecting input iterator to output iterator
    By QuestionC in forum C++ Programming
    Replies: 2
    Last Post: 04-10-2007, 02:18 AM
  3. New system build wont boot
    By lightatdawn in forum Tech Board
    Replies: 7
    Last Post: 12-02-2005, 06:58 AM
  4. Why Can't C++ Be Used to Develop Operating System?
    By Antigloss in forum C++ Programming
    Replies: 7
    Last Post: 05-27-2005, 06:16 AM
  5. System Commands Output
    By nasir_qau in forum Linux Programming
    Replies: 2
    Last Post: 03-21-2002, 03:14 PM