Skip to content

Commit 842b802

Browse files
committed
process IO: add test for #22832
Fixes #14747
1 parent b4855b6 commit 842b802

File tree

2 files changed

+19
-23
lines changed

2 files changed

+19
-23
lines changed

base/shell.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -285,11 +285,11 @@ This function may be useful in concert with the `windows_verbatim` flag to
285285
286286
```julia
287287
wincmd(c::String) =
288-
run(Cmd(Cmd(["cmd.exe", "/s /c \" \$c \""]);
288+
run(Cmd(Cmd(["cmd.exe", "/s /c \\" \$c \\""]);
289289
windows_verbatim=true))
290290
wincmd_echo(s::String) =
291291
wincmd("echo " * Base.shell_escape_wincmd(s))
292-
wincmd_echo("hello \$(ENV["USERNAME"]) & the \"whole\" world! (=^I^=)")
292+
wincmd_echo("hello \$(ENV["USERNAME"]) & the \\"whole\\" world! (=^I^=)")
293293
```
294294
295295
But take note that if the input string `s` contains a `%`, the argument list
@@ -316,7 +316,7 @@ run(setenv(`cmd /C echo %cmdargs%`, "cmdargs" => cmdargs))
316316
```julia
317317
to_print = "All for 1 & 1 for all!"
318318
to_print_esc = Base.shell_escape_wincmd(Base.shell_escape_wincmd(to_print))
319-
run(Cmd(Cmd(["cmd", "/S /C \" break | echo \$(to_print_esc) \""]), windows_verbatim=true))
319+
run(Cmd(Cmd(["cmd", "/S /C \\" break | echo \$(to_print_esc) \\""]), windows_verbatim=true))
320320
```
321321
322322
With an I/O stream parameter `io`, the result will be written there,

test/read.jl

+16-20
Original file line numberDiff line numberDiff line change
@@ -98,30 +98,27 @@ s = io(text)
9898
close(s)
9999
push!(l, ("PipeEndpoint", io))
100100

101-
#FIXME See https://github.com/JuliaLang/julia/issues/14747
102-
# Reading from open(::Command) seems to deadlock on Linux
103-
#=
104-
if !Sys.iswindows()
105101

106-
# Windows type command not working?
107-
# See "could not spawn `type 'C:\Users\appveyor\AppData\Local\Temp\1\jul3516.tmp\file.txt'`"
108-
#https://ci.appveyor.com/project/StefanKarpinski/julia/build/1.0.12733/job/hpwjs4hmf03vs5ag#L1244
109-
110-
# Pipe
102+
# Pipe (#14747)
111103
io = (text) -> begin
112104
write(filename, text)
113-
open(`$(Sys.iswindows() ? "type" : "cat") $filename`)[1]
114-
# Was open(`echo -n $text`)[1]
115-
# See https://github.com/JuliaLang/julia/issues/14747
105+
# we can skip using shell_escape_wincmd, since ", ^, and % aren't legal in
106+
# a filename, so unconditionally wrapping in " is sufficient (okay, that's
107+
# a lie, since ^ and % actually are legal, but DOS is broken)
108+
if Sys.iswindows()
109+
cmd = Cmd(["cmd.exe", "/c type \"$(replace(filename, '/' => '\\'))\""])
110+
cmd = Cmd(cmd; windows_verbatim=true)
111+
cmd = pipeline(cmd, stderr=devnull)
112+
else
113+
cmd = `cat $filename`
114+
end
115+
open(cmd)
116116
end
117117
s = io(text)
118118
@test isa(s, IO)
119-
@test isa(s, Pipe)
119+
@test isa(s, Base.Process)
120120
close(s)
121-
push!(l, ("Pipe", io))
122-
123-
end
124-
=#
121+
push!(l, ("Process", io))
125122

126123

127124
open_streams = []
@@ -140,7 +137,6 @@ end
140137
verbose = false
141138

142139
for (name, f) in l
143-
local f
144140
local function io(text=text)
145141
local s = f(text)
146142
push!(open_streams, s)
@@ -319,9 +315,9 @@ for (name, f) in l
319315
text = old_text
320316
write(filename, text)
321317

322-
if !(typeof(io()) in [Base.PipeEndpoint, Pipe, TCPSocket])
318+
if !isa(io(), Union{Base.PipeEndpoint, Base.AbstractPipe, TCPSocket})
323319
verbose && println("$name position...")
324-
@test (s = io(); read!(s, Vector{UInt8}(undef, 4)); position(s)) == 4
320+
@test (s = io(); read!(s, Vector{UInt8}(undef, 4)); position(s)) == 4
325321

326322
verbose && println("$name seek...")
327323
for n = 0:length(text)-1

0 commit comments

Comments
 (0)