Thread: data manipulation between C program & linux shell

  1. #1
    Registered User
    Join Date
    Jun 2010
    Posts
    18

    data manipulation between C program & linux shell

    Dear all,

    I've to develop a software, which works on the data taken from Linux shell commands. For example: manipulation of the output of ifconfig command into C/C++ program. How this can be achieved?
    I know that system() function can be used to execute linux commands. But don't know how to return the output to program.

    Or, are there any others way of doing it?

    Note: Only high level languages preferred. No scripting

    Thank you
    Last edited by sangamesh; 09-04-2010 at 12:56 PM. Reason: Matter modification

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    Look into popen()

    Jim

  3. #3
    Third Eye Babkockdood's Avatar
    Join Date
    Apr 2010
    Posts
    352
    Try doing a system command that writes the output of ifconfig to a file, then have the program read the output file.

    Code:
    int main() {
         FILE *in;
         system("ifconfig > /tmp/crap");
         in = fopen("/tmp/crap", "r");
         /* code code code... */
         fclose(in);
         remove("/tmp/crap");
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. My Program Won't Display First Few Data...
    By nino613 in forum C Programming
    Replies: 2
    Last Post: 12-08-2009, 01:50 PM
  2. Replies: 48
    Last Post: 09-26-2008, 03:45 AM
  3. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 12:39 PM
  4. How To Embed Data In Program While Compile?
    By ooosawaddee3 in forum C++ Programming
    Replies: 1
    Last Post: 09-09-2002, 10:14 AM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM