Question

How do I execute below mentioned command using exec inside a C language program in linux?

wget -P ./Folder http://www.google.com

Était-ce utile?

La solution 2

I've find this solution for the problem and it worked in my case.

char *args[] = {"/usr/bin/wget", "-P","./Folder", "http://www.google.com", (char *) 0 };

execv("/usr/bin/wget", args);

And another solution to this is to directly run the command with system function like:

system(wget -P ./Folder http://www.google.com)

Autres conseils

execl("/usr/bin/wget", "-P", "./Folder", "http://www.google.com", NULL);

Unless you have to use exec, I suggest using system from libc, since it is more portable (in case you ever decide you want to port it).

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top