Skip to content

Commit 0712f9c

Browse files
committed
add deprecation mechanism for (io,p) = open(cmd)
1 parent 50e12f3 commit 0712f9c

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

base/deprecated.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,16 @@ end
770770
const FloatingPoint = AbstractFloat
771771
export FloatingPoint
772772

773+
# 12807
774+
775+
start(::Union(Process, ProcessChain)) = 1
776+
done(::Union(Process, ProcessChain), i::Int) = i == 3
777+
next(p::Union(Process, ProcessChain), i::Int) = (getindex(p, i), i+1)
778+
@noinline function getindex(p::Union(Process, ProcessChain), i::Int)
779+
depwarn("open(cmd) now returns only a Process <: IO object", :getindex)
780+
return i == 1 ? p.(p.openstream) : p
781+
end
782+
773783
# 11447
774784

775785
@noinline function Regex(pattern::AbstractString, options::Integer)

base/process.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ type Process <: AbstractPipe
212212
exitnotify::Condition
213213
closecb::Callback
214214
closenotify::Condition
215+
openstream::Symbol # for open(cmd) deprecation
215216
function Process(cmd::Cmd, handle::Ptr{Void}, in::RawOrBoxedHandle, out::RawOrBoxedHandle, err::RawOrBoxedHandle)
216217
if !isa(in, AsyncStream) || in === DevNull
217218
in=DevNull
@@ -236,7 +237,9 @@ immutable ProcessChain <: AbstractPipe
236237
in::Redirectable
237238
out::Redirectable
238239
err::Redirectable
240+
openstream::Symbol # for open(cmd) deprecation
239241
ProcessChain(stdios::StdIOSet) = new(Process[], stdios[1], stdios[2], stdios[3])
242+
ProcessChain(chain::ProcessChain, openstream::Symbol) = new(chain.processes, chain.in, chain.out, chain.err, openstream) # for open(cmd) deprecation
240243
end
241244

242245
function _jl_spawn(cmd, argv, loop::Ptr{Void}, pp::Process,
@@ -477,11 +480,21 @@ function open(cmds::AbstractCmd, mode::AbstractString="r", other::AsyncStream=De
477480
out = Pipe()
478481
processes = spawn(cmds, (in,out,STDERR))
479482
close(out.in)
483+
if isa(processes,ProcessChain) # for open(cmd) deprecation
484+
processes = ProcessChain(processes, :out)
485+
else
486+
processes.openstream = :out
487+
end
480488
elseif mode == "w"
481489
in = Pipe()
482490
out = other
483491
processes = spawn(cmds, (in,out,STDERR))
484492
close(in.out)
493+
if isa(processes,ProcessChain) # for open(cmd) deprecation
494+
processes = ProcessChain(processes, :in)
495+
else
496+
processes.openstream = :in
497+
end
485498
else
486499
throw(ArgumentError("mode must be \"r\" or \"w\", not \"$mode\""))
487500
end

0 commit comments

Comments
 (0)