# Getting hold of error status from an external command?

**URL:** https://discourse.julialang.org/t/getting-hold-of-error-status-from-an-external-command/126465
**Category:** General Usage
**Tags:** run, external-process
**Created:** [March 2, 2025, 3:50am UTC](https://discourse.julialang.org/t/getting-hold-of-error-status-from-an-external-command/126465 "2025-03-02T03:50:55Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![ryofurue](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ryofurue/32/24531_2.png) [@ryofurue](https://discourse.julialang.org/u/ryofurue)
#### Post date: [March 2, 2025, 3:50am UTC](https://discourse.julialang.org/t/getting-hold-of-error-status-from-an-external-command/126465/1 "2025-03-02T03:50:55Z")

</div>

I found the following old thread discussing the same problem. Is this

```julia
proc = spawn(pipeline(ignorestatus(cmd)))

```

still the best way to get hold of the exit code?

I wish these commands (`run()` etc) had an option to return a proc object instead of throwing an exception.

> [@How to handle error statuses and exit codes in Julia while invoking external commands?](https://discourse.julialang.org/t/how-to-handle-error-statuses-and-exit-codes-in-julia-while-invoking-external-commands/9768):
>
> 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, 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: ![PeterSimon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petersimon/32/25193_2.png) [@PeterSimon](https://discourse.julialang.org/u/PeterSimon)
#### Post date: [March 2, 2025, 4:43am UTC](https://discourse.julialang.org/t/getting-hold-of-error-status-from-an-external-command/126465/2 "2025-03-02T04:43:19Z")

</div>

I do it like this:

```julia
julia> cmd = Cmd(`which`; ignorestatus=true)
`which`

julia> t = run(cmd)

?Invalid usage. Type 'WHICH -?' for help

julia> t.exitcode
2

```

---

<div class="post-metadata">

### Author: ![ryofurue](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ryofurue/32/24531_2.png) [@ryofurue](https://discourse.julialang.org/u/ryofurue)
#### Post date: [March 2, 2025, 4:57am UTC](https://discourse.julialang.org/t/getting-hold-of-error-status-from-an-external-command/126465/3 "2025-03-02T04:57:39Z")

</div>

Thanks!!! That means that I haven’t found the right documentation or the documentation hasn’t been updated.

---

<div class="post-metadata">

### Author: ![PeterSimon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petersimon/32/25193_2.png) [@PeterSimon](https://discourse.julialang.org/u/PeterSimon)
#### Post date: [March 2, 2025, 5:20am UTC](https://discourse.julialang.org/t/getting-hold-of-error-status-from-an-external-command/126465/4 "2025-03-02T05:20:47Z")

</div>

See the documentation for [`Cmd`](https://docs.julialang.org/en/v1/base/base/#Base.Cmd).

Edit: yeah, I’m not seeing where the output of the `run` function is documented. That probably means that my solution is brittle.

---

<div class="post-metadata">

### Author: ![Octogonapus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/octogonapus/32/9489_2.png) [@Octogonapus](https://discourse.julialang.org/u/Octogonapus)
#### Post date: [March 6, 2025, 10:53pm UTC](https://discourse.julialang.org/t/getting-hold-of-error-status-from-an-external-command/126465/5 "2025-03-06T22:53:51Z")

</div>

It’s documented [here](https://docs.julialang.org/en/v1/base/parallel/#Base.wait). Checking `exitcode` is the correct way.

---

<div class="post-metadata">

### Author: ![PeterSimon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petersimon/32/25193_2.png) [@PeterSimon](https://discourse.julialang.org/u/PeterSimon)
#### Post date: [March 6, 2025, 11:04pm UTC](https://discourse.julialang.org/t/getting-hold-of-error-status-from-an-external-command/126465/6 "2025-03-06T23:04:02Z")

</div>

Nice find!
