LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   how to give commands inside program (http://www.linuxquestions.org/questions/programming-9/how-to-give-commands-inside-program-638348/)

sarathius 04-28-2008 05:31 AM

how to give commands inside program
 
How to give command inside the C program and hoe to fetch the value. I need the mac address of the system. So, i will give "ifconfig" command and i can able to find the MAC address. I want to give this command inside the program and fetch the MAC address alone.. How to do this..

Anyone help me in this issue...

Thanks in advance...

smus 04-28-2008 06:25 AM

you can directly call system command like system('cmd') or may be you can use snprintf IO function.

paulsm4 04-28-2008 01:17 PM

Quote:

man popen
Code:

  FILE *pipe;
  char buff[256];

  pipe = popen ("/sbin/ifconfig", "r");
  if (pipe == NULL)
    ... error handling ...
  while (!feof (pipe))
  {
    if (fgets (buff, sizeof (buff), pipe) <= 0)
      continue;
    ... parse input ...
  }
  pclose (pipe);



All times are GMT -5. The time now is 12:38 AM.