My execvp
is not running ls -l *.c
command. I have tried to use two methods :
- One with the file path where my ls is located which is in
\bin\ls
.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(void)
{
char *cmdargs[] = { "ls", "-l", "*.c", NULL };
pid_t pid;
pid = fork();
if (pid == 0)
execvp("\bin\ls", cmdargs);
else
{
wait(NULL);
printf("Child terminates\n");
}
return 0;
}
Output :
ls: *.c: No such file or directory
Child terminates
- The second method I used was to add
cmdargs[0]
instead of the file path.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(void)
{
char *cmdargs[] = { "ls", "-l", "*.c", NULL };
pid_t pid;
pid = fork();
if (pid == 0)
execvp(cmdargs[0], cmdargs);
else
{
wait(NULL);
printf("Child terminates\n");
}
return 0;
}
Output:
ls: *.c: No such file or directory
Child terminates
When I just run the command ls -l *.c
, it does show me all the files which end with .c
. Execvp does not show me the files. There was a question related to this but that did not help me.