# How to handle error statuses and exit codes in Julia while invoking external commands?

**URL:** <https://discourse.julialang.org/t/how-to-handle-error-statuses-and-exit-codes-in-julia-while-invoking-external-commands/9768>\
**Category:** General Usage\
**Tags:** question, query\
**Created:** [March 17, 2018, 7:48am UTC](https://discourse.julialang.org/t/how-to-handle-error-statuses-and-exit-codes-in-julia-while-invoking-external-commands/9768 "2018-03-17T07:48:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rahulkp220](https://avatars.discourse-cdn.com/v4/letter/r/3da27b/32.png) [@rahulkp220](https://discourse.julialang.org/u/rahulkp220)\
**Post date:** [March 17, 2018, 7:48am UTC](https://discourse.julialang.org/t/how-to-handle-error-statuses-and-exit-codes-in-julia-while-invoking-external-commands/9768/1 "2018-03-17T07:48:29Z")

</div>

Hi, I am trying to run an external command from Julia using the `run()` function, but I am stuck on how to handle error codes and exit codes of any particular command. Previous Julia version had a `readall()` function, which isn’t available anymore.

Something like,

```julia
stdout,stderr = run(`some command`)

```

Although I do get the `stacktrace` and `error` printed on the console.(May be the default behaviour causes it to dump everything to `STDOUT`)

---

<div class="post-metadata">

**Author:** ![Ralph\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ralph_smith/32/10344_2.png) [@Ralph\_Smith](https://discourse.julialang.org/u/Ralph_Smith)\
**Post date:** [March 17, 2018, 5:03pm UTC](https://discourse.julialang.org/t/how-to-handle-error-statuses-and-exit-codes-in-julia-while-invoking-external-commands/9768/2 "2018-03-17T17:03:27Z")

</div>

`run` is not very flexible.  
The following seems to work on v0.6.2 and a recent nightly:

```julia
    cmd = `some command`
    err = Pipe()
    out = Pipe()
    proc = spawn(pipeline(ignorestatus(cmd),stdout=out,stderr=err))
    close(err.in)
    close(out.in)
    println("stdout: ",String(read(out)))
    println("stderr: ",String(read(err)))
    println("status: ",proc.exitcode)

```

I don’t know if this is recommended usage, but it is based on what I learned from the test suite.

---

<div class="post-metadata">

**Author:** ![rahulkp220](https://avatars.discourse-cdn.com/v4/letter/r/3da27b/32.png) [@rahulkp220](https://discourse.julialang.org/u/rahulkp220)\
**Post date:** [March 17, 2018, 6:32pm UTC](https://discourse.julialang.org/t/how-to-handle-error-statuses-and-exit-codes-in-julia-while-invoking-external-commands/9768/3 "2018-03-17T18:32:55Z")

</div>

@Ralph_Smith This was really helpful and helped me get running with the code. Thanks a lot!
