Skip to content
Advertisement

how to read output of system(‘ls’)?

I am doing some file IO with c code. I have a particular pattern in my file. I can verify this by a shell command cat abc.txt | grep abc | wc -l. When I execute the same command using System(), it give proper output, but I have no clue how can I get its output into a variable and compare it in my c code itself.

I tried looking into man pages which suggest using WEXITSTATUS(). This actually returns the status of execution and not output.

F1 !!

Advertisement

Answer

You don’t want system(3) for that. Try popen(3) and friends.

Advertisement