# Julia test process exit status

**URL:** <https://discourse.julialang.org/t/julia-test-process-exit-status/23557>\
**Category:** New to Julia\
**Tags:** shell, error\
**Created:** [April 26, 2019, 1:30pm UTC](https://discourse.julialang.org/t/julia-test-process-exit-status/23557 "2019-04-26T13:30:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Luigi\_Marongiu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/luigi_marongiu/32/7909_2.png) [@Luigi\_Marongiu](https://discourse.julialang.org/u/Luigi_Marongiu)\
**Post date:** [April 26, 2019, 1:30pm UTC](https://discourse.julialang.org/t/julia-test-process-exit-status/23557/1 "2019-04-26T13:30:50Z")

</div>

Dear all,  
I am trying to run shell commands via julia so to move from bash to julia altogether. However, I need to check the exit status of the commands launched. I tried the tips given [in this post](https://discourse.julialang.org/t/how-to-handle-error-statuses-and-exit-codes-in-julia-while-invoking-external-commands/9768/2) but did not work. For instance, how can I get the exit status of a simple `ls` command?

```julia
julia> cmd = `ls ./`
julia> run(cmd)
readSelection.jl doSomething.jl rslt.txt
Process(`ls ./`, ProcessExited(0))

```

but:

```julia
julia> err = Pipe()
julia> out = Pipe()
julia> proc = spawn(pipeline(ignorestatus(cmd),stdout=out,stderr=err))
ERROR: UndefVarError: spawn not defined
Stacktrace:
 [1] top-level scope at none:0

```

thus the rest of the code was not executed:

```julia
julia> close(err.in)
julia> close(out.in)
julia> println("stdout: ",String(read(out)))
julia> println("stderr: ",String(read(err)))
julia> println("status: ",proc.exitcode)

```

Why is `spawn` not defined? Is it possible to get the `ProcessExited(0)` string generated by `run`?  
Thanks

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [April 26, 2019, 1:44pm UTC](https://discourse.julialang.org/t/julia-test-process-exit-status/23557/2 "2019-04-26T13:44:44Z")

</div>

`spawn(::Cmd)` was deprecated in Julia 0.7. If you run the code in Julia 0.7 you get the following warning:

```julia
Warning: `spawn(cmds::AbstractCmd)` is deprecated,
         use `run(cmds, wait=false)` instead.

```

so you should use `run(::Cmd; wait=false)` as an replacement.

---

<div class="post-metadata">

**Author:** ![Luigi\_Marongiu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/luigi_marongiu/32/7909_2.png) [@Luigi\_Marongiu](https://discourse.julialang.org/u/Luigi_Marongiu)\
**Post date:** [April 26, 2019, 2:14pm UTC](https://discourse.julialang.org/t/julia-test-process-exit-status/23557/3 "2019-04-26T14:14:59Z")

</div>

Thank you, but how do I capture the exit status?  
I tried with

```julia
proc=run(cmd, stdout=out,stderr=err; wait=false)
ERROR: MethodError: no method matching run(::Cmd; stdout=Pipe(RawFD(0xffffffff) init => RawFD(0xffffffff) init, 0 bytes waiting), stderr=Pipe(RawFD(0xffffffff) init => RawFD(0xffffffff) init, 0 bytes waiting), wait=false)
Closest candidates are:
  run(::Base.AbstractCmd, ::Any...; wait) at process.jl:661 got unsupported keyword arguments "stdout", "stderr"
Stacktrace:
 [1] kwerr(::NamedTuple{(:stdout, :stderr, :wait),Tuple{Pipe,Pipe,Bool}}, ::Function, ::Cmd) at ./error.jl:97
 [2] (::getfield(Base, Symbol("#kw##run")))(::NamedTuple{(:stdout, :stderr, :wait),Tuple{Pipe,Pipe,Bool}}, ::typeof(run), ::Cmd) at ./none:0
 [3] top-level scope at none:0

```

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [April 26, 2019, 2:20pm UTC](https://discourse.julialang.org/t/julia-test-process-exit-status/23557/4 "2019-04-26T14:20:04Z")

</div>

```julia
julia> proc = run(`ls`; wait=false)
Process(`ls`, ProcessRunning)

julia> proc.exitcode
0

```

If you just want to make sure the exit code is 0 you can use `success`.

---

<div class="post-metadata">

**Author:** ![Luigi\_Marongiu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/luigi_marongiu/32/7909_2.png) [@Luigi\_Marongiu](https://discourse.julialang.org/u/Luigi_Marongiu)\
**Post date:** [April 26, 2019, 2:43pm UTC](https://discourse.julialang.org/t/julia-test-process-exit-status/23557/5 "2019-04-26T14:43:05Z")

</div>

Thank you!
