# What kind of julia object translates to C's FILE\*

**URL:** <https://discourse.julialang.org/t/what-kind-of-julia-object-translates-to-cs-file/77656>\
**Category:** General Usage\
**Tags:** ccall, libcurl\
**Created:** [March 9, 2022, 11:36pm UTC](https://discourse.julialang.org/t/what-kind-of-julia-object-translates-to-cs-file/77656 "2022-03-09T23:36:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bluesmoon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bluesmoon/32/327_2.png) [@bluesmoon](https://discourse.julialang.org/u/bluesmoon)\
**Post date:** [March 9, 2022, 11:36pm UTC](https://discourse.julialang.org/t/what-kind-of-julia-object-translates-to-cs-file/77656/1 "2022-03-09T23:36:11Z")

</div>

I’m on Julia 1.6.5 and trying to redirect verbose messages from `LibCURL` to a file. In `C` this would be done by calling `curl_easy_setopt(CURL *handle, CURLOPT_STDERR, FILE *stream)`.

What kind of a Julia object should I pass in as `FILE *stream`? Ideally I’d be able to use either a file or an in-memory `IOStream`.

Note that I don’t want to capture all of `stderr` (eg: using `redirect_stderr`), I just need to capture `curl`’s verbose output while allowing all other stderr output to keep going to `stderr`.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [March 10, 2022, 1:01am UTC](https://discourse.julialang.org/t/what-kind-of-julia-object-translates-to-cs-file/77656/2 "2022-03-10T01:01:35Z")

</div>

> [@bluesmoon](#):
>
> What kind of a Julia object should I pass in as `FILE *stream` ? Ideally I’d be able to use either a file or an in-memory `IOStream` .

A `Libc.FILE` object, which you can create from an `io::IO` object (such as a file or a pipe) by `f = Libc.FILE(io)`. (I think you have to manually call `close(f)` when you are done with it, because the constructor duplicates the file descriptor ([julia#10535](https://github.com/JuliaLang/julia/pull/10535))?)

See also [How to create Libc.FILE from a string](https://discourse.julialang.org/t/how-to-create-libc-file-from-a-string/36637), [Access C stdout in Julia](https://discourse.julialang.org/t/access-c-stdout-in-julia/24187), and [Libc.FILE for stdout](https://discourse.julialang.org/t/libc-file-for-stdout/22482)

---

<div class="post-metadata">

**Author:** ![bluesmoon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bluesmoon/32/327_2.png) [@bluesmoon](https://discourse.julialang.org/u/bluesmoon)\
**Post date:** [March 10, 2022, 1:54am UTC](https://discourse.julialang.org/t/what-kind-of-julia-object-translates-to-cs-file/77656/3 "2022-03-10T01:54:05Z")

</div>

Ah, I think I was missing the `close` so it was probably not getting flushed.
