Solved

Getting the output of an external program

Posted on 2007-04-04
2
194 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Problem with MFCApp 78 383
Understanding the meaning of Portability in Embedded System Programming 8 143
convert char array to number in c 5 85
An API detour question 7 85
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 tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.

770 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