Try redirect_stderr:
http://docs.julialang.org/en/latest/stdlib/io-network/#Base.redirect_stderr

On Fri, Jul 3, 2015 at 10:25 PM, Ben Ward <[email protected]> wrote:

> Hi,
>
> I want to run an external command in Julia. Should a command fail I want
> to get the message from the external command.
>
> I know failed commands raise a general exception that can be caught:
>
> *run(`dat hi`)*
>
> dat: hi is not a valid command
>
> *ERROR: failed process: Process(`dat hi`, ProcessExited(1)) [1]*
>
> * in run at ./process.jl:490*
>
> I see that a message is printed out by the external program:
>
> dat: hi is not a valid command.
>
> However readall() does not get this message and return it as a string:
>
> *readall(`dat hi`)*
>
> dat: hi is not a valid command
>
> *ERROR: failed process: Process(`dat hi`, ProcessExited(1)) [1]*
>
> * in readbytes at process.jl:474*
>
> * in readall at process.jl:479*
>
> Is there a way I can capture this message at all and report it back to the
> user as part of a try-catch upon catching of the ProcessExited(1) exception?
>
> Thanks,
> Ben.
>

Reply via email to