How to handle certain output from eval_string

I write the result to stdout and if I get something like IO.puts() then I write it’s output to stderr.
Like this:

{result, _} = Code.eval_string(code)
if code has IO.puts() then write it to stderr end
wrtie result to stdout