Skip to content

Commit

Permalink
add deprecation mechanism for (io,p) = open(cmd)
Browse files Browse the repository at this point in the history
  • Loading branch information
vtjnash committed Aug 27, 2015
1 parent a9e9358 commit db79a03
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
10 changes: 10 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -783,3 +783,13 @@ function Regex(pattern::AbstractString, options::Integer)
"use string flags instead: Regex(\"$pattern\", \"$flags\").", :Regex)
Regex(pattern, flags)
end

# 12807

start(::Union(Process, ProcessChain)) = 1
done(::Union(Process, ProcessChain), i::Int) = i == 3
next(p::Union(Process, ProcessChain), i::Int) = (getindex(p, i), i+1)
@noinline function getindex(p::Union(Process, ProcessChain), i::Int)
depwarn("open(cmd) now returns only a Process <: IO object", :getindex)
return i == 1 ? p.(p.openstream) : p
end
13 changes: 13 additions & 0 deletions base/process.jl
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ type Process <: AbstractPipe
exitnotify::Condition
closecb::Callback
closenotify::Condition
openstream::Symbol # for open(cmd) deprecation
function Process(cmd::Cmd, handle::Ptr{Void}, in::RawOrBoxedHandle, out::RawOrBoxedHandle, err::RawOrBoxedHandle)
if !isa(in, AsyncStream) || in === DevNull
in=DevNull
Expand All @@ -236,7 +237,9 @@ immutable ProcessChain <: AbstractPipe
in::Redirectable
out::Redirectable
err::Redirectable
openstream::Symbol # for open(cmd) deprecation
ProcessChain(stdios::StdIOSet) = new(Process[], stdios[1], stdios[2], stdios[3])
ProcessChain(chain::ProcessChain, openstream::Symbol) = new(chain.processes, chain.in, chain.out, chain.err, openstream) # for open(cmd) deprecation
end

function _jl_spawn(cmd, argv, loop::Ptr{Void}, pp::Process,
Expand Down Expand Up @@ -477,11 +480,21 @@ function open(cmds::AbstractCmd, mode::AbstractString="r", other::AsyncStream=De
out = Pipe()
processes = spawn(cmds, (in,out,STDERR))
close(out.in)
if isa(processes,ProcessChain) # for open(cmd) deprecation
processes = ProcessChain(processes, :out)
else
processes.openstream = :out
end
elseif mode == "w"
in = Pipe()
out = other
processes = spawn(cmds, (in,out,STDERR))
close(in.out)
if isa(processes,ProcessChain) # for open(cmd) deprecation
processes = ProcessChain(processes, :in)
else
processes.openstream = :in
end
else
throw(ArgumentError("mode must be \"r\" or \"w\", not \"$mode\""))
end
Expand Down

0 comments on commit db79a03

Please sign in to comment.