I know I can do
execl("/bin/ls","-l",(char*)NULL)
to output ls.
But how do I execute
ls | grep -c "file"
using execv
? In my code I want to search my current working directory for a particular file name. The above command returns 1 if the file exists and 0 if it doesn't. I want to execute this command from my program using execv
. How do I do this?
I tried
execl("/bin/ls", "| grep -c file" ,(char*)NULL)
But it doesn't work.
Also, even if I execute this command using execl
, it will just print the output number in the terminal. How do I get it to return it to the program?