Skip to content

Commit db79a03

Browse files
committed
add deprecation mechanism for (io,p) = open(cmd)
1 parent a9e9358 commit db79a03

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
@@ -783,3 +783,13 @@ function Regex(pattern::AbstractString, options::Integer)
783783
"use string flags instead: Regex(\"$pattern\", \"$flags\").", :Regex)
784784
Regex(pattern, flags)
785785
end
786+
787+
# 12807
788+
789+
start(::Union(Process, ProcessChain)) = 1
790+
done(::Union(Process, ProcessChain), i::Int) = i == 3
791+
next(p::Union(Process, ProcessChain), i::Int) = (getindex(p, i), i+1)
792+
@noinline function getindex(p::Union(Process, ProcessChain), i::Int)
793+
depwarn("open(cmd) now returns only a Process <: IO object", :getindex)
794+
return i == 1 ? p.(p.openstream) : p
795+
end

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)