Skip to content

Commit

Permalink
Add try/finally to @capture
Browse files Browse the repository at this point in the history
  • Loading branch information
j-fu committed Sep 14, 2020
1 parent 65a271f commit 1a194cc
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/Capture.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,16 @@ macro capture(expr)
original_stdout = stdout
out_rd, out_wr = redirect_stdout()
reader = @async read(out_rd)
# Redirect both logging output and print(stderr,...)
# to stdout
with_logger(SimpleLogger(stdout)) do
redirect_stderr(()->$(esc(expr)),stdout)
end
redirect_stdout(original_stdout)
close(out_wr)
try
# Redirect both logging output and print(stderr,...)
# to stdout
with_logger(SimpleLogger(stdout)) do
redirect_stderr(()->$(esc(expr)),stdout)
end
finally
redirect_stdout(original_stdout)
close(out_wr)
end
String(fetch(reader))
end
end
Expand Down

0 comments on commit 1a194cc

Please sign in to comment.