0

I am currently working on a prgram for Linux which downloads data from a webserver. I achieved this with system("wget <url etc...>") and it seems to work fine as it just gets the job done.

However I read that calling wget through a system call is considered bad practice and you should instead use a library like libcurl. But I don't understand why writing 10 to 15 lines (in libcurl) of code to download a file is better than a single line of wget with the same result.

Amplify
  • 865
  • 1
  • 8
  • 18
  • 1
    As long as you measure code quality in terms of lines of code, you will probably never find any other argument convincing. – Kerrek SB Apr 03 '16 at 20:07
  • 3
    libcurl will give you better control over the `GET` request regarding error handling and such. Anyway it totally depends on your use case what fits better. – πάντα ῥεῖ Apr 03 '16 at 20:07
  • I think you should go for libcurl . Running on different machines or platforms may cause error this way . In the long term, it's a bad practice I believe . Some of the alternatives to libcurl or wget you can use : https://curl.haxx.se/libcurl/competitors.html – saruftw Apr 03 '16 at 20:08
  • Also see [this answer](http://stackoverflow.com/a/4622772/33499) – wimh Apr 03 '16 at 20:10
  • The excellent comments above would create a definitive answer for this question :) – Moo-Juice Apr 03 '16 at 20:13
  • Following the "fail fast" approach, if you use libcurl but it isn't installed your application will not compile. If you use wget but it isn't installed your application will fail at runtime. – MrEricSir Apr 03 '16 at 20:16
  • I also found [this](http://stackoverflow.com/questions/22669642/using-the-libcurl-library-vs-calling-curl-using-system) question which also answered my question. I will try to get into libcurl as soon as possible. Thanks for your replies! – Amplify Apr 03 '16 at 20:27
  • To summarize, `system` (or `fork`/`exec`/`wait` without its shell-related vulnerabilities) is "good enough" as a "quick and dirty" solution but problematic in the long run. – ivan_pozdeev Apr 03 '16 at 20:28
  • 1
    Why should the program care where the data is? Read it from stdin, you can always use wget or curl to pipe it in. – Joni Apr 03 '16 at 20:48

0 Answers0