wget output in memory/variable

I am using wget in .c file and executing with system("wget http://example.com");
it is working fine but the output is saved to file or stderr how do i redirect to buffer in .c program
tittuAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
woolmilkporcConnect With a Mentor Commented:
Hi,
you can use a 'popen' call -
#include <stdio.h>

main()
{
  FILE *fptr;
  char line[130]; /* line from wget*/
   
  fptr = popen("wget http://example.com", "r"); /* Issue the wget command. */

/* Read a line */
  while ( fgets( line, sizeof line, fptr))
  {
    printf("%s", line);

/* or process the 'line' otherwise as needed */
  }
  pclose(fptr);
}
 
0
 
evilrixSenior Software Engineer (Avast)Commented:
Have you considered using libcurl to do this?
http://curl.haxx.se/libcurl/

0
 
tittuAuthor Commented:
thanks
0
 
woolmilkporcCommented:
Any reason for grade B?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.