Skip to content

Commit

Permalink
fix #32193, consistent errors from open on commands (#32832)
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson authored Aug 11, 2019
1 parent 987a3d6 commit 2e971e8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ Standard library changes
* `mod` now accepts a unit range as the second argument to easily perform offset modular arithmetic to ensure the result is inside the range ([#32628]).
* `Sockets.recvfrom` now returns both host and port as an InetAddr ([#32729]).
* `nothing` can now be `print`ed, and interplated into strings etc. as the string `"nothing"`. It is still not permitted to be interplated into Cmds (i.e. ``echo `$(nothing)` `` will still error without running anything.) ([#32148])
* When `open` is called with a function, command, and keyword argument (e.g. ```open(`ls`, read=true) do f ...```)
it now correctly throws a `ProcessFailedException` like other similar calls ([#32193]).

#### Libdl

Expand Down
8 changes: 4 additions & 4 deletions base/process.jl
Original file line number Diff line number Diff line change
Expand Up @@ -381,14 +381,14 @@ function open(cmds::AbstractCmd, stdio::Redirectable=devnull; write::Bool=false,
end

"""
open(f::Function, command, mode::AbstractString="r", stdio=devnull)
open(f::Function, command, args...; kwargs...)
Similar to `open(command, mode, stdio)`, but calls `f(stream)` on the resulting process
Similar to `open(command, args...; kwargs...)`, but calls `f(stream)` on the resulting process
stream, then closes the input stream and waits for the process to complete.
Returns the value returned by `f`.
"""
function open(f::Function, cmds::AbstractCmd, args...)
P = open(cmds, args...)
function open(f::Function, cmds::AbstractCmd, args...; kwargs...)
P = open(cmds, args...; kwargs...)
ret = try
f(P)
catch
Expand Down
7 changes: 7 additions & 0 deletions test/spawn.jl
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,13 @@ open(`$catcmd`, "r+") do f
wait(t)
end

# issue #32193
mktemp() do path, io
redirect_stderr(io) do
@test_throws ProcessFailedException open(identity, `$catcmd _doesnt_exist__111_`, read=true)
end
end

let text = "input-test-text"
b = PipeBuffer()
proc = open(Base.CmdRedirect(Base.CmdRedirect(```$exename --startup-file=no -E '
Expand Down

0 comments on commit 2e971e8

Please sign in to comment.