LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices



Reply
 
Search this Thread
Old 04-28-2008, 05:31 AM   #1
sarathius
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, 06:25 AM   #2
smus
Member
 
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, 01:17 PM   #3
paulsm4
Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

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

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


Reply


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-13-2007 12:31 AM
where to place certiain commands inside shell script beeblequix Linux - Newbie 8 08-10-2006 12:12 PM
execution of one program inside of another microsoft/linux Programming 2 03-18-2005 11:24 AM
c++ uses system to give commands to bash darkRoom Programming 2 03-10-2005 05:27 AM
Is it possible to give MSDOS commands in Unix script??? gopi_20us Programming 1 02-20-2002 01:48 AM


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

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