• C

Getting the output of an external program

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.



LVL 1
help-meAsked:
Who is Participating?
 
ozoCommented:
FILE *F= popen("ls -l", "r");
fread(buffer,1,sizeof(buffer),F);
0
 
help-meAuthor Commented:
tested..... its works!!  cool!!

Thanks a lot!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.