I have developed the following code: main:
#include<stdio.h>
#include<unistd.h>
int main()
{
char *const args[] = {"/bin/ls", "> test.txt 2>&1", NULL};
execvp(args[0], args);
/* If this is reached execvp failed. */
perror("execvp");
return 0;
}
I need to execute this shell command : /bin/ls > test.txt 2>&1
but I have got an error:
$gcc -o main main.c
$ vi main.c
$ gcc -o main main.c
$ ./main
/bin/ls: cannot access '> test.txt 2>&1': No such file or directory
$
Why it returns /bin/ls: cannot access '> test.txt 2>&1': No such file or directory ? Have you a solution to fix that ?