How can I hide curl_easy_perform output (in a shell)?
This is in regards to a C application.
views:
141answers:
2
+2
A:
Set the CURLOPT_WRITEFUNCTION
and/or CURLOPT_WRITEDATA
options:
FILE *f = fopen("target.txt", "wb");
curl_easy_setopt(handle, CURLOPT_WRITEDATA, f);
By default, libcurl writes output to stdout
. When you override this (which is what almost any application will do), it will write to another file or to pass chunks of output to a callback. See the documentation for curl_easy_setopt
for more details.
Joey Adams
2010-05-11 23:00:17
Thanks, but I know this. There isn't a way without "deviate" the output (a way to delete it)?
stdio
2010-05-11 23:41:11
@stdio - If you just want the input to go away, open a NULL device and print everything there.
Tim Post
2010-05-12 00:27:25
@Tm Post: do you mean /dev/null? if you mean this, the code would not be multiplatform.
stdio
2010-05-12 00:48:25
+1
A:
As Joey said, CURLOPT_WRITEFUNCTION
will allow you to completely disregard all output. Just set up a callback that does absolutely nothing if you want the data to just go away, without being written to any file descriptor.
For instance,
/* Never writes anything, just returns the size presented */
size_t my_dummy_write(void *ptr, size_t size, size_t nmemb, FILE *stream)
{
return size;
}
Then in your options:
curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, &my_dummy_write);
Or, point the file handle at a NULL device (a lot easier).
Tim Post
2010-05-12 00:33:14