Thread: Getting System Output into C

  1. #1
    Registered User
    Join Date
    Sep 2007
    Posts
    4

    Getting System Output into C

    Hi folks,

    I am newbie to Linux programming but not a Linux newbie. I am writing a C program for gathering statistical data from remote Linux machines. I need to know how can I call other executables and store the results into a character array.

    Example:
    I want to obtain the total system memory status. If this was at the command line, I would write
    Code:
    free -m
    and this will display the current memory status.

    However, I want to be able to make this call from my C program and store the result into a character array.

    I've looked into the exec set of functions but none of these allow me to store the output of the commands I pass as parameters into my character array.

    Any help is appreciated!

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Perhaps use the popen() call?
    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.

  3. #3
    Registered User
    Join Date
    Sep 2007
    Posts
    4
    Quote Originally Posted by Salem View Post
    Perhaps use the popen() call?

    Thank you! That was eye opening!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Having trouble making a function do what I want.
    By Shamino in forum C++ Programming
    Replies: 9
    Last Post: 12-07-2007, 11:20 AM
  2. New system build wont boot
    By lightatdawn in forum Tech Board
    Replies: 7
    Last Post: 12-02-2005, 06:58 AM
  3. 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
  4. Base converter libary
    By cdonlan in forum C++ Programming
    Replies: 22
    Last Post: 05-15-2005, 01:11 AM
  5. System Commands Output
    By nasir_qau in forum Linux Programming
    Replies: 2
    Last Post: 03-21-2002, 03:14 PM