如何在linux中使用exec命令使用wget命令?

时间:2014-03-02 05:56:18

标签: c linux exec wget

如何在linux中的C语言程序中使用exec执行下面提到的命令?

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

2 个答案:

答案 0 :(得分:1)

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

除非你必须使用exec,否则我建议你使用libc中的system,因为它更便携(如果你决定要移植它)。

答案 1 :(得分:0)

我已经找到了解决这个问题的方案,并且在我的案例中也有效。

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

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

另一个解决方案是使用系统函数直接运行命令,如:

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