Last active
August 26, 2022 01:36
-
-
Save rlb3/a096141d8821a7572f835cbbdfb0fad2 to your computer and use it in GitHub Desktop.
In iex redirect stdio to file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Console.Helpers do | |
defmacro capture_io(filename, do: block) do | |
quote do | |
filename = unquote(filename) | |
current_leader = Process.group_leader() | |
{:ok, fh} = File.open(filename, [:write]) | |
Process.group_leader(self(), fh) | |
unquote(block) | |
Process.group_leader(self(), current_leader) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment