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
:
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> 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> 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?