Solved

Getting the output of an external program

Posted on 2007-04-04
2
192 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
Comment Utility
FILE *F= popen("ls -l", "r");
fread(buffer,1,sizeof(buffer),F);
0
 
LVL 1

Author Comment

by:help-me
Comment Utility
tested..... its works!!  cool!!

Thanks a lot!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

762 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now