Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Getting the output of an external program

Posted on 2007-04-04
2
195 Views
Last Modified: 2012-05-05
Hi experts,

I need a program that does the following in linux:
Run an external program eg. system("ls -l") and then parse the output of the external program.

One way is to redirect the output of external program to a file and then my program parse the file.
However, I need to do this many times in the program and need it to be fast.

Is there anyway in C I can get the output of the external program straight into an array in my program?
Cause I don't want to first write to a file and then later open the file and parse it (too slow).

Thanks.



0
Comment
Question by:help-me
2 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 50 total points
ID: 18855858
FILE *F= popen("ls -l", "r");
fread(buffer,1,sizeof(buffer),F);
0
 
LVL 1

Author Comment

by:help-me
ID: 18855949
tested..... its works!!  cool!!

Thanks a lot!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question