0

I am trying to execute the cp command with two options --preserve and --interactive

And in my code I have:

char const *copy[] = {"/bin/cp","cp","-p","-i",0};

execv(copy[0],copy);

But it is giving me this error

error: invalid conversion from 'const char**' to 'char* const*'   
error: initializing argument 2 of 'int execv(const char*, char* const*)'

What should I change for this to work?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Pro
  • 173
  • 4
  • 15

1 Answers1

0

I believe you should declare copy as:

char *const copy[] = {"/bin/cp", "cp", "-p", "-i", 0};

See: http://pubs.opengroup.org/onlinepubs/009695399/functions/exec.html