# Write to file and stdout

**URL:** <https://discourse.julialang.org/t/write-to-file-and-stdout/35042>\
**Category:** General Usage\
**Tags:** question, io\
**Created:** [February 23, 2020, 4:38am UTC](https://discourse.julialang.org/t/write-to-file-and-stdout/35042 "2020-02-23T04:38:58Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [February 23, 2020, 5:47am UTC](https://discourse.julialang.org/t/write-to-file-and-stdout/35042/3 "2020-02-23T05:47:21Z")

</div>

This needs a lot more work to define a proper IO interface, but

```julia
struct Tee{TIO <: Tuple} <: IO
    streams::TIO
end

Tee(streams...) = Tee(streams)

function _do_tee(tee, f, xs...)
    for io in tee.streams
        f(io, xs...)
    end
end

Base.write(tee::Tee, x) = _do_tee(tee, write, x)
Base.write(tee::Tee, x::Union{SubString{String},String}) = _do_tee(tee, write, x)

print(Tee(stdout, stderr), "will appear twice")

```

---

_[View the full topic](https://discourse.julialang.org/t/write-to-file-and-stdout/35042)._
