Welcome to the most active Linux Forum on the web.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 04-28-2008, 04:31 AM   #1
LQ Newbie
Registered: Jan 2008
Posts: 12

Rep: Reputation: 0
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...
Old 04-28-2008, 05:25 AM   #2
Registered: Nov 2005
Location: Turkey
Distribution: Suse
Posts: 104

Rep: Reputation: 16
you can directly call system command like system('cmd') or may be you can use snprintf IO function.
Old 04-28-2008, 12:17 PM   #3
LQ Guru
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
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);

Last edited by paulsm4; 04-28-2008 at 12:19 PM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
RE in commands like match() inside awk. stalin.varanasi Linux - Newbie 2 12-12-2007 11:31 PM
where to place certiain commands inside shell script beeblequix Linux - Newbie 8 08-10-2006 11:12 AM
execution of one program inside of another microsoft/linux Programming 2 03-18-2005 10:24 AM
c++ uses system to give commands to bash darkRoom Programming 2 03-10-2005 04:27 AM
Is it possible to give MSDOS commands in Unix script??? gopi_20us Programming 1 02-20-2002 12:48 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:56 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration