system() function ?

익명 사용자의 이미지

I want to get result value system func.
i.e.
system( " wc -l < a.sam | awk '{print $1}' )

this system function results in integer value. ( = line count of sam file )

How can I get this value? ( using gets? ,,, help me )

-- I want to write in hangul, but I can't now in this system. sorry.

익명 사용자의 이미지

use popen...^^

show you example ..

#include
#include
main()
{
char *cmd = "/usr/bin/ls *.c";
char buf[BUFSIZ];
FILE *ptr;

if ((ptr = popen(cmd, "r")) != NULL)
while (fgets(buf, BUFSIZ, ptr) != NULL)
(void) printf("%s", buf);
return 0;
}