Skip to content

Commit

Permalink
fixup! alter open(command) do to close the whole process afterwards
Browse files Browse the repository at this point in the history
  • Loading branch information
vtjnash committed Apr 2, 2021
1 parent 6e6c84e commit fad03c7
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions base/process.jl
Original file line number Diff line number Diff line change
Expand Up @@ -384,19 +384,23 @@ end
open(f::Function, command, args...; kwargs...)
Similar to `open(command, args...; kwargs...)`, but calls `f(stream)` on the
resulting process stream, then closes the I/O streams and waits for the process
resulting process stream, then closes the input stream and waits for the process
to complete. Return the value returned by `f` on success. Throw an error if the
process failed.
process failed, or if the process attempts to print anything to stdout.
"""
function open(f::Function, cmds::AbstractCmd, args...; kwargs...)
P = open(cmds, args...; kwargs...)
ret = try
f(P)
catch
kill(P)
rethrow()
finally
close(P)
rethrow()
end
close(P.in)
if !eof(P.out)
close(P.out)
throw(_UVError("open(do)", UV_EPIPE))
end
success(P) || pipeline_error(P)
return ret
Expand Down

0 comments on commit fad03c7

Please sign in to comment.