Skip to content

Commit 79ea87f

Browse files
authored
Merge pull request #22762 from JuliaLang/jb/readcmd
RFC: deprecate reading functions that accept both a cmd and stdin
2 parents f6e55a7 + 1a8da5f commit 79ea87f

File tree

4 files changed

+13
-15
lines changed

4 files changed

+13
-15
lines changed

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@ Deprecated or removed
167167
and `is_windows`, have been deprecated in favor of `Sys.islinux`, `Sys.isbsd`, `Sys.isapple`,
168168
`Sys.isunix`, and `Sys.iswindows`, respectively ([#22182]).
169169

170+
* The forms of `read`, `readstring`, and `eachline` that accepted both a `Cmd` object and an
171+
input stream are deprecated. Use e.g. `read(pipeline(stdin, cmd))` instead ([#22762]).
172+
170173

171174
Julia v0.6.0 Release Notes
172175
==========================

base/deprecated.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1583,6 +1583,10 @@ end
15831583
@deprecate is_unix Sys.isunix
15841584
@deprecate is_windows Sys.iswindows
15851585

1586+
@deprecate read(cmd::AbstractCmd, stdin::Redirectable) read(pipeline(stdin, cmd))
1587+
@deprecate readstring(cmd::AbstractCmd, stdin::Redirectable) readstring(pipeline(stdin, cmd))
1588+
@deprecate eachline(cmd::AbstractCmd, stdin; chomp::Bool=true) eachline(pipeline(stdin, cmd), chomp=chomp)
1589+
15861590
# END 0.7 deprecations
15871591

15881592
# BEGIN 1.0 deprecations

base/process.jl

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -553,16 +553,15 @@ spawn_opts_inherit(in::Redirectable=RawFD(0), out::Redirectable=RawFD(1), err::R
553553
spawn(cmds::AbstractCmd, args...; chain::Nullable{ProcessChain}=Nullable{ProcessChain}()) =
554554
spawn(cmds, spawn_opts_swallow(args...)...; chain=chain)
555555

556-
function eachline(cmd::AbstractCmd, stdin; chomp::Bool=true)
556+
function eachline(cmd::AbstractCmd; chomp::Bool=true)
557557
stdout = Pipe()
558-
processes = spawn(cmd, (stdin,stdout,STDERR))
558+
processes = spawn(cmd, (DevNull,stdout,STDERR))
559559
close(stdout.in)
560560
out = stdout.out
561561
# implicitly close after reading lines, since we opened
562562
return EachLine(out, chomp=chomp,
563563
ondone=()->(close(out); success(processes) || pipeline_error(processes)))::EachLine
564564
end
565-
eachline(cmd::AbstractCmd; chomp::Bool=true) = eachline(cmd, DevNull, chomp=chomp)
566565

567566
# return a Process object to read-to/write-from the pipeline
568567
"""
@@ -642,22 +641,14 @@ function readandwrite(cmds::AbstractCmd)
642641
return (processes.out, processes.in, processes)
643642
end
644643

645-
function read(cmd::AbstractCmd, stdin::Redirectable=DevNull)
646-
procs = open(cmd, "r", stdin)
644+
function read(cmd::AbstractCmd)
645+
procs = open(cmd, "r", DevNull)
647646
bytes = read(procs.out)
648647
success(procs) || pipeline_error(procs)
649648
return bytes
650649
end
651650

652-
function readstring(cmd::AbstractCmd, stdin::Redirectable=DevNull)
653-
return String(read(cmd, stdin))
654-
end
655-
656-
function writeall(cmd::AbstractCmd, stdin::AbstractString, stdout::Redirectable=DevNull)
657-
open(cmd, "w", stdout) do io
658-
write(io, stdin)
659-
end
660-
end
651+
readstring(cmd::AbstractCmd) = String(read(cmd))
661652

662653
"""
663654
run(command, args...)

doc/src/manual/running-external-programs.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ will attempt to store the data in the kernel's buffers while waiting for a reade
313313
Another common solution is to separate the reader and writer of the pipeline into separate Tasks:
314314

315315
```julia
316-
writer = @async writeall(process, "data")
316+
writer = @async write(process, "data")
317317
reader = @async do_compute(readstring(process))
318318
wait(process)
319319
fetch(reader)

0 commit comments

Comments
 (0)