LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   C: Getting program's output (https://www.linuxquestions.org/questions/programming-9/c-getting-programs-output-294384/)

MylesCLin 02-24-2005 12:14 PM

C: Getting program's output
 
Is there any way, in C, to execute another program AND get it's output?
I need to run wc -c to get the number of chars in a file.
Any ideas?

itsme86 02-24-2005 12:19 PM

Look at the popen() function.

Matir 02-24-2005 12:20 PM

Look into popen();.

Though a more portable way to do this would be:
Code:

long filelen(char *fname){
long len;
FILE *f=fopen(fname,"r");
fseek(f,0,SEEK_END);
len=ftell(f);
fclose(f);
return len;
}

Or something similar. Been a while since I've done that in C.

MylesCLin 02-24-2005 12:35 PM

You have fixed my problem, danke sehrs!

Matir 02-24-2005 05:06 PM

No problem. :) Just glad to help.


All times are GMT -5. The time now is 12:27 AM.