Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

hide curl_easy_perform

Tags:

c

libcurl

How can I hide curl_easy_perform output (in a shell)?
This is in regards to a C application.

like image 276
stdio Avatar asked May 11 '10 22:05

stdio


2 Answers

Use CURLOPT_NOBODY in curl_easy_setopt(). Example:

 ...

CURL *curl;
CURLcode statusCode;

curl = curl_easy_init();
if(curl){
    curl_easy_setopt(curl, CURLOPT_URL, "http://www.google.com/");
    //CURLOPT_NOBODY does the trick
    curl_easy_setopt(curl, CURLOPT_NOBODY, 1);
    curl_easy_perform(curl);

 ...

Link to docs: http://curl.haxx.se/libcurl/c/curl_easy_setopt.html#CURLOPTNOBODY

like image 84
Paul Semionov Avatar answered Oct 14 '22 00:10

Paul Semionov


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 CURLOPT_WRITEFUNCTION for more details.

like image 15
Joey Adams Avatar answered Oct 14 '22 00:10

Joey Adams