function with_out_str(f::Function)
  orig_stdout = STDOUT
  rd, wr = redirect_stdout()
  f()
  redirect_stdout(orig_stdout)
  return readavailable(rd)
end

macro with_out_str(expr)
  :(with_out_str(()->$expr)) |> esc
end

You can use this as

@with_out_str begin
  ... code ...
end

But I think you'll need to change "stdout" to "stderr" in the above 
definition to capture warnings.

On Friday, 20 June 2014 21:35:51 UTC+1, Laszlo Hars wrote:
>
> Could someone help with redirecting stderr? For example, the following 
> code does not get the error message shown in the Julia console in Windows 
> 7, Julia Version 0.3.0-prerelease+3789:
> ~~~
> stderr_orig = STDERR
> rd, wr = redirect_stderr()
> 1^-1
> close(wr)
> eof(rd)
> close(rd)
> out = readall(rd)
> redirect_stderr(stderr_orig)
> ~~~
>
> On Friday, June 20, 2014 8:36:44 AM UTC-6, Jameson wrote:
>>
>> You could redirect_stderr and test for content writte 
>
>

Reply via email to