Skip to content

Commit 06a2be1

Browse files
committed
add deprecation mechanism for (io,p) = open(cmd)
1 parent 81dbe44 commit 06a2be1

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

base/deprecated.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1307,6 +1307,15 @@ end
13071307
end
13081308
end
13091309

1310+
# 12807
1311+
start(::Union{Process, ProcessChain}) = 1
1312+
done(::Union{Process, ProcessChain}, i::Int) = (i == 3)
1313+
next(p::Union{Process, ProcessChain}, i::Int) = (getindex(p, i), i + 1)
1314+
@noinline function getindex(p::Union{Process, ProcessChain}, i::Int)
1315+
depwarn("open(cmd) now returns only a Process<:IO object", :getindex)
1316+
return i == 1 ? getfield(p, p.openstream) : p
1317+
end
1318+
13101319
# PR #16984
13111320
@deprecate MersenneTwister() MersenneTwister(0)
13121321

base/process.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ mutable struct Process <: AbstractPipe
315315
termsignal::Int32
316316
exitnotify::Condition
317317
closenotify::Condition
318+
openstream::Symbol # for open(cmd) deprecation
318319
function Process(cmd::Cmd, handle::Ptr{Void},
319320
in::Union{Redirectable, Ptr{Void}},
320321
out::Union{Redirectable, Ptr{Void}},
@@ -344,7 +345,9 @@ struct ProcessChain <: AbstractPipe
344345
in::Redirectable
345346
out::Redirectable
346347
err::Redirectable
348+
openstream::Symbol # for open(cmd) deprecation
347349
ProcessChain(stdios::StdIOSet) = new(Process[], stdios[1], stdios[2], stdios[3])
350+
ProcessChain(chain::ProcessChain, openstream::Symbol) = new(chain.processes, chain.in, chain.out, chain.err, openstream) # for open(cmd) deprecation
348351
end
349352
pipe_reader(p::ProcessChain) = p.out
350353
pipe_writer(p::ProcessChain) = p.in
@@ -589,11 +592,21 @@ function open(cmds::AbstractCmd, mode::AbstractString="r", other::Redirectable=D
589592
out = Pipe()
590593
processes = spawn(cmds, (in,out,STDERR))
591594
close(out.in)
595+
if isa(processes, ProcessChain) # for open(cmd) deprecation
596+
processes = ProcessChain(processes, :out)
597+
else
598+
processes.openstream = :out
599+
end
592600
elseif mode == "w"
593601
in = Pipe()
594602
out = other
595603
processes = spawn(cmds, (in,out,STDERR))
596604
close(in.out)
605+
if isa(processes, ProcessChain) # for open(cmd) deprecation
606+
processes = ProcessChain(processes, :in)
607+
else
608+
processes.openstream = :in
609+
end
597610
else
598611
throw(ArgumentError("mode must be \"r\" or \"w\", not \"$mode\""))
599612
end

0 commit comments

Comments
 (0)