I am trying to make a program that will copy file1 into file2 the following way:cp -i -p file1 file2Now I call my executable copy and so by calling copy file1 file2It will do the same thing like the first command (-i and -p).I was able to do this using execlchar const *copy[] = {/bin/cp,cp,-p,-i,0};execl(copy[0],copy[1],copy[2],copy[3],argv[1],argv[2],copy[4]);However, I want to do it now with execvI saw the man page of exec* functionsexecl(const char *path, const char *arg, ...);execv(const char *path, char *const argv[]);and so the first argument seems to be the same however,How the second argument for execv is char *const argv[]what do I need to change in the execv function to get the same result ?I have my main function arguments like the following:main(int argc,char * argv[])
How can I succesfully call the execv function?
command line;cp;c;arguments;exec
Change your copy array, and the function call. The following is a minimal example:#include <unistd.h>int main(int arcg, char *argv[]){    char *const args[] = {cp,-p,-i, argv[1], argv[2], 0};     execv(/bin/cp, args);}