LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 06-05-2003, 07:38 PM   #1
Linh
Member
 
Registered: Apr 2003
Posts: 178

Rep: Reputation: 30
How to run a shell command containing awk, and grep within a C program


1) #include <stdio.h>
2) #include <stdlib.h>
3) int system(const char *string1);

4) int main()
5) {
6) char c;
7) char string1[] = "ifconfig";
8) system(string1);

9) char linux_command[] = "ifconfig eth0 | grep eth0 | awk '{print $5}'";
10) system(linux_command);

10) execlp ("bin/bash", "bash", "-c", linux_command, (char *) 0);
11) return(0);
12) }
========================================

1) Line 7 and 8 worked. The ouput did get printed on the screen.
2) Line 9 and 10 do not worked, because awk, and grep are involved. How do I get it to work ?

3) On line 10, what is execlp ? How do I use it ? Is the syntax on line 10 is correct ?
I got line 10 example from a book, but it does not explain very clearly.
 
Old 06-05-2003, 07:52 PM   #2
fancypiper
Guru
 
Registered: Feb 2003
Location: Sparta, NC USA
Distribution: Ubuntu 10.04
Posts: 5,141

Rep: Reputation: 58
Did you read the rules you agreed to?
 
Old 06-05-2003, 08:00 PM   #3
Linh
Member
 
Registered: Apr 2003
Posts: 178

Original Poster
Rep: Reputation: 30
There is no vulgarity in my question. It is all C programming.
 
Old 06-05-2003, 08:05 PM   #4
fancypiper
Guru
 
Registered: Feb 2003
Location: Sparta, NC USA
Distribution: Ubuntu 10.04
Posts: 5,141

Rep: Reputation: 58
Quote:
# Do not post the same discussion in more than one forum. Duplicate discussions can be frustrating for other members. Try and pick the most relevant forum for your post. If you are unsure put it in Linux - General.
 
  


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
Can I use grep inside awk? Helene Programming 6 04-27-2004 01:58 AM
Viewing program messages when program isn't run from command line? Locura Linux - Software 1 09-27-2003 09:19 AM
newbie needs help for grep and awk parker Programming 1 08-12-2003 05:24 AM
Running a shell command containing awk and grep within a C program Linh Programming 1 06-05-2003 07:51 PM
How do I zip and attach the output data of a grep | awk | mail shell script? 360 Programming 1 05-08-2002 09:26 AM


All times are GMT -5. The time now is 03:39 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