Skip to content

Commit 2e971e8

Browse files
authored
fix #32193, consistent errors from open on commands (#32832)
1 parent 987a3d6 commit 2e971e8

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ Standard library changes
5656
* `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]).
5757
* `Sockets.recvfrom` now returns both host and port as an InetAddr ([#32729]).
5858
* `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])
59+
* When `open` is called with a function, command, and keyword argument (e.g. ```open(`ls`, read=true) do f ...```)
60+
it now correctly throws a `ProcessFailedException` like other similar calls ([#32193]).
5961

6062
#### Libdl
6163

base/process.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -381,14 +381,14 @@ function open(cmds::AbstractCmd, stdio::Redirectable=devnull; write::Bool=false,
381381
end
382382

383383
"""
384-
open(f::Function, command, mode::AbstractString="r", stdio=devnull)
384+
open(f::Function, command, args...; kwargs...)
385385
386-
Similar to `open(command, mode, stdio)`, but calls `f(stream)` on the resulting process
386+
Similar to `open(command, args...; kwargs...)`, but calls `f(stream)` on the resulting process
387387
stream, then closes the input stream and waits for the process to complete.
388388
Returns the value returned by `f`.
389389
"""
390-
function open(f::Function, cmds::AbstractCmd, args...)
391-
P = open(cmds, args...)
390+
function open(f::Function, cmds::AbstractCmd, args...; kwargs...)
391+
P = open(cmds, args...; kwargs...)
392392
ret = try
393393
f(P)
394394
catch

test/spawn.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,13 @@ open(`$catcmd`, "r+") do f
627627
wait(t)
628628
end
629629

630+
# issue #32193
631+
mktemp() do path, io
632+
redirect_stderr(io) do
633+
@test_throws ProcessFailedException open(identity, `$catcmd _doesnt_exist__111_`, read=true)
634+
end
635+
end
636+
630637
let text = "input-test-text"
631638
b = PipeBuffer()
632639
proc = open(Base.CmdRedirect(Base.CmdRedirect(```$exename --startup-file=no -E '

0 commit comments

Comments
 (0)