Way to store what is normally printed in the REPL to a string or file?

I specifically want to store the outputs of @code_warntype to a string or file so I can read through it later, but I’m also interested in doing something similar for any expression that prints to the REPL.

1 Like

code_warntype lets you pass an IO object as the first argument so you can do something like this:

julia> f(x, y) = x * y;

julia> open("file.txt", "w") do io
           code_warntype(io, f, Tuple{Int, Int})
       end
$ cat file.txt
Variables
  #self#::Core.Compiler.Const(f, false)
  x::Int64
  y::Int64

Body::Int64
1 ─ %1 = (x * y)::Int64
└──      return %1
4 Likes

I totally forgot about the function code_warntype. Considering that print and other similar functions all have that IO option, I’m figuring that there’s the only way to specify where the printed content goes; can’t change it after the fact.