-   Programming (
-   -   how to give commands inside program (

sarathius 04-28-2008 04: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 05:25 AM

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

paulsm4 04-28-2008 12:17 PM


man popen

  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)
    ... parse input ...
  pclose (pipe);

All times are GMT -5. The time now is 11:52 AM.