The function execvp expects each argument as a separate argument in the array passed in. You are passing 'vars' as a single argument that has spaces in it. Grep is waiting for input from standard input(the console here) and is searching for lines containing 'a search.txt'. The following program does what you expect.
#include "unistd.h"
int main(void)
{
char * executable = "grep";
char *arg[] = { executable, "a","search.txt", NULL };
execvp(executable, arg);
return 0;
}
By passing the searched for string as its own argument, grep treats the next argument in the list as a file to search.
Here is what that program does for me:
ericu@eric-phenom-linux:~$ gcc -o execgrep /home/ericu/execgrep.c
ericu@eric-phenom-linux:~$ ./execgrep
a
abc
ericu@eric-phenom-linux:~$ cat search.txt
c
b
a
abc
ericu@eric-phenom-linux:~$
Modifying the sample program to mirror what you are currently doing
#include "unistd.h"
int main(void)
{
char * executable = "grep";
char *arg[] = { executable, "a search.txt", NULL };
execvp(executable, arg);
return 0;
}
Results in a program that expects input from standard input.
ericu@eric-phenom-linux:~$ echo -e "Review the man page from proper usage of execvp.a search.txt\nThis line does not show up in the output" | ./execgrep
Review the man page from proper usage of execvp.a search.txt
ericu@eric-phenom-linux:~$