# Running an external program with non-zero return values

**URL:** <https://discourse.julialang.org/t/running-an-external-program-with-non-zero-return-values/68057>\
**Category:** General Usage\
**Tags:** question\
**Created:** [September 12, 2021, 6:11pm UTC](https://discourse.julialang.org/t/running-an-external-program-with-non-zero-return-values/68057 "2021-09-12T18:11:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pfarndt](https://avatars.discourse-cdn.com/v4/letter/p/8dc957/32.png) [@pfarndt](https://discourse.julialang.org/u/pfarndt)\
**Post date:** [September 12, 2021, 6:11pm UTC](https://discourse.julialang.org/t/running-an-external-program-with-non-zero-return-values/68057/1 "2021-09-12T18:11:50Z")

</div>

I want to parse a diff from two versions of a file. Thought to do this by running `diff` as an external program and reading its output into a `String`:

```julia
read(`diff version1.txt version2.txt`, String)

```

This works fine and returns `""` if both files have the same contents. However if the files differ julia throws an error

```julia
julia> read(`diff version1.txt version2.txt`, String)
ERROR: failed process: Process(`diff version1.txt version2.txt`, ProcessExited(1)) [1]

```

because the return value of the diff command is `1` if it finds differences. Even trying to catch this error does not provide me the output of the command:

```julia
julia> a = try read(`diff version1.txt version2.txt`, String)
       catch
       end

julia> 

```

How can I read output of `bash` commands with non-zero return values?

---

<div class="post-metadata">

**Author:** ![greg\_plowman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/greg_plowman/32/8100_2.png) [@greg\_plowman](https://discourse.julialang.org/u/greg_plowman)\
**Post date:** [September 12, 2021, 10:17pm UTC](https://discourse.julialang.org/t/running-an-external-program-with-non-zero-return-values/68057/2 "2021-09-12T22:17:43Z")

</div>

I’m not sure if there’s a built-in way to by-pass checking the return status.

EDIT: see the following post - wrap the command in `ignorestatus`

```julia
  ignorestatus(command)

  Mark a command object so that running it will not throw an error if the result code is non-zero.

```

Here’s the code that’s run (from `process.jl`)

```julia
read(cmd::AbstractCmd, ::Type{String}) = String(read(cmd))::String

function read(cmd::AbstractCmd)
    procs = open(cmd, "r", devnull)
    bytes = read(procs.out)
    success(procs) || pipeline_error(procs)
    return bytes
end

```

Maybe write your own customized version that omits checking the return status?

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [September 12, 2021, 10:20pm UTC](https://discourse.julialang.org/t/running-an-external-program-with-non-zero-return-values/68057/3 "2021-09-12T22:20:52Z")

</div>

> [@pfarndt](#):
>
> `read(`diff version1.txt version2.txt`, String)`

```julia
read(ignorestatus(`diff version1.txt version2.txt`), String)

```
