cURL / Mailing Lists / curl-users / Single Mail

curl-users

Re: reading a log file while open

From: Ray Satiro via curl-users <curl-users_at_cool.haxx.se>
Date: Fri, 22 Apr 2016 15:25:42 -0400

On 4/22/2016 2:17 AM, Daniel Stenberg wrote:
> On Fri, 22 Apr 2016, Francisco Gonzalez Velasco wrote:
>
>> C:\>curl -o c:\q\events.txt -k -H "Authorization: Bearer
>> My_Authorization" " https://stream-fxpractice.oanda.com/v1/events"
>>
>> I need to read the contents of the events.txt file while the cURL
>> process is still active.
>>
>> Is this possible?
>
> That's not curl making it hard, that's Windows for you. Any other
> operating system would let you read the file while another process is
> writing to it...
>
> So, you need to consider a work-around. Maybe pipe curl's output into
> your programs stdin isntead? Or maybe consider using libcurl and get
> the data downloaded directly within your application?
>

It's likely not that he can't read the file but instead he reads the
file and it doesn't have the latest information due to buffering.

Francisco try --no-buffer [1][2] which should help. A program like
Notepad++ will detect when the file is updated and should offer to
reload it.

Also instead as Leif mentioned you could use tee to write the output to
the console and append it to a file at the same time. You can find tee
for Windows in gnuwin32 build of coreutils [3]. Extract tee.exe,
libintl3.dll and libiconv2.dll from the bin dir in
coreutils-5.3.0-dep.zip and coreutils-5.3.0-bin.zip. Then you pipe curl
to tee, tee writes to the file but also outputs to the console:

curl --silent --no-buffer -H "Authorization: Bearer My_Authorization"
https://stream-fxpractice.oanda.com/v1/events | tee --append c:\q\events.txt

And I suggest you don't use the -k switch, when you do that you're
disabling the certificate check. If there's a certificate problem
correct it!

[1]: https://curl.haxx.se/docs/manpage.html#-N
[2]:
https://github.com/curl/curl/blob/curl-7_48_0/src/tool_cb_wrt.c#L151-L156
[3]: https://sourceforge.net/projects/gnuwin32/files/coreutils/5.3.0/

-------------------------------------------------------------------
List admin: https://cool.haxx.se/list/listinfo/curl-users
FAQ: https://curl.haxx.se/docs/faq.html
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2016-04-22