~~~ errormsg = @with_out_str begin ... code ... end ~~~ should put the error message into errormsg.
-- Leah On Fri, Jun 20, 2014 at 4:29 PM, Laszlo Hars <laszloh...@gmail.com> wrote: > I am confused: I can change all the "out"s to "err"s, but what variable > will contain the error message to be inspected? The error messages seem to > only appear in the console, nowhere else. > > > On Friday, June 20, 2014 2:47:28 PM UTC-6, Mike Innes wrote: >> >> 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 >>> >>>