curl / Mailing Lists / curl-users / Single Mail

curl-users

Re: libcurl newbie question on output

From: Malcolm MacArthur <macartm_at_gmail.com>
Date: Sun, 15 Apr 2018 10:02:09 +0100

Hi,

I know nothing about using the library (I just use the tool) but my hunch
is because you didn't tell it to put it anywhere it defaults to stdout (so
it goes somewhere). You could confirm whether it's going to stdout or
stderr using shell redirection

your_program 1> stdout.txt 2> stderr.txt

(If it ends up in neither file, it may be opening another stream. That's
also possible but probably unlikely)

So ... if I were you, I'd check the documentation to see about how to put
the output elsewhere. Sounds like you've been reading along the right
tracks when you talk about setting up a callback function to receive the
data.

Perhaps there are easier ways to do it though, such as set an option to
tell it to go to a file that you then fopen()? Like I said, I don't know.
Maybe someone who knows will chip in :-)

Malcolm

On Sun, Apr 15, 2018 at 1:01 AM, Lonnie Cumberland <lonnie_at_outstep.com>
wrote:

> Hello All,
>
> I am new to using libcurl and have been able to compile up a number of
> examples with no problems.
>
> As an example:
>
> ---------------------------------
>
> */***************************************************************************
> * _ _ ____ _
> * Project ___| | | | _ \| |
> * / __| | | | |_) | |
> * | (__| |_| | _ <| |___
> * \___|\___/|_| \_\_____|
> *
> * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel_at_haxx.se <daniel_at_haxx.se>>, et al.
> *
> * This software is licensed as described in the file COPYING, which
> * you should have received as part of this distribution. The terms
> * are also available at https://curl.haxx.se/docs/copyright.html <https://curl.haxx.se/docs/copyright.html>.
> *
> * You may opt to use, copy, modify, merge, publish, distribute and/or sell
> * copies of the Software, and permit persons to whom the Software is
> * furnished to do so, under the terms of the COPYING file.
> *
> * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
> * KIND, either express or implied.
> *
> ***************************************************************************/ **/* <DESC>
> * simple HTTP POST using the easy interface
> * </DESC>
> */ *
> #*include* *<stdio.h>*
> #*include* *<curl/curl.h>*
> *int* *main*(*void*)
> {
> CURL *curl;
> CURLcode res;
>
> */* In windows, this will init the winsock stuff */ *
> curl_global_init <https://curl.haxx.se/libcurl/c/curl_global_init.html>(CURL_GLOBAL_ALL);
>
> */* get a curl handle */ *
> curl = curl_easy_init <https://curl.haxx.se/libcurl/c/curl_easy_init.html>();
> *if*(curl) {
> */* First set the URL that is about to receive our POST. This URL can
> just as well be a https:// URL if that is what should receive the
> data. */ *
> curl_easy_setopt <https://curl.haxx.se/libcurl/c/curl_easy_setopt.html>(curl, CURLOPT_URL <https://curl.haxx.se/libcurl/c/CURLOPT_URL.html>, *"http://postit.example.com/moo.cgi <http://postit.example.com/moo.cgi>"*);
> */* Now specify the POST data */ *
> curl_easy_setopt <https://curl.haxx.se/libcurl/c/curl_easy_setopt.html>(curl, CURLOPT_POSTFIELDS <https://curl.haxx.se/libcurl/c/CURLOPT_POSTFIELDS.html>, *"name=daniel&project=curl"*);
>
> */* Perform the request, res will get the return code */ *
> res = curl_easy_perform <https://curl.haxx.se/libcurl/c/curl_easy_perform.html>(curl);
> */* Check for errors */ *
> *if*(res != CURLE_OK)
> fprintf(stderr, *"curl_easy_perform <https://curl.haxx.se/libcurl/c/curl_easy_perform.html>() failed: %s\n"*,
> curl_easy_strerror <https://curl.haxx.se/libcurl/c/curl_easy_strerror.html>(res));
>
> */* always cleanup */ *
> curl_easy_cleanup <https://curl.haxx.se/libcurl/c/curl_easy_cleanup.html>(curl);
> }
> curl_global_cleanup <https://curl.haxx.se/libcurl/c/curl_global_cleanup.html>();
> *return* 0;
> }
>
>
> ---------------------------------
>
> When this is compiled and runs, it goes out to the example site and get
> the data as it should but then it is printing it to the console (Ubuntu
> 16.04).
>
> I'm a bit rusty on my C/C++ and am getting back into things, but what I
> see that only "fprintf" function that should display something if there is
> an error to the "stderr" device.
>
> Where is the code setting that is sending the URL data to the console and
> can that be turned off, or on, as needed?
>
> Other examples seem to show how to setup a callback function that can
> actually receive the data and move it to a memory pointer so that you can
> work with it and I am looking into that as well.
>
> Any help would be greatly appreciated.
> Thanks
> Lonnie
>
>
>
> -----------------------------------------------------------
> Unsubscribe: https://cool.haxx.se/list/listinfo/curl-users
> Etiquette: https://curl.haxx.se/mail/etiquette.html
>
>

-----------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-users
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2018-04-15