FIFOStreams
FIFOStreams.FIFOStream
โ TypeFIFOStream(path::String=_mktemp(); read=false, write=!read, cleanup=true)
-> UnixFIFOStream (on Unix) / FallbackFIFOStream (on non-Unix)
An abstract type for either writing to, or reading from external commands through Unix pipes or temporary files. All subtypes T<:FIFOStream
implement the following interface:
- Create stream
s
, optionally from specific path:s = T([path::String]; opts...)
- Attach an external command that reads from / writes to that path:
attach(s, `foo $(path(s))`[, stdios...])
- Write to / read from the stream, just like any other
IO
object - Close the stream with
close(s; rm=s.cleanup)
Examples
julia> s = FIFOStream();
julia> io = IOBuffer();
julia> attach(s, pipeline(`cat $(path(s))`, stdout=io));
julia> print(s, "Hello, World!")
julia> close(s)
julia> Text(String(take!(io)))
Hello, World!
julia> s = FIFOStream(read=true);
julia> attach(s, `bash -c "echo 'Hello, World!' > $(path(s))"`);
julia> read(s, String)
"Hello, World!\n"
julia> close(s)
FIFOStreams.FIFOStreamCollection
โ TypeFIFOStreamCollection([T::Type{<:FIFOStream}, ]n::Integer; opts...)
A collection of multiple FIFOStream
s, for dealing with multiple streams conveniently.
Examples
julia> s = FIFOStreamCollection(2);
julia> io = IOBuffer();
julia> attach(s, pipeline(ignorestatus(`diff --side-by-side $(path(s, 1)) $(path(s, 2))`); stdout=io));
julia> s1, s2 = s;
julia> show(s1, code_lowered(cos, Tuple{Float64}))
julia> show(s2, code_lowered(sin, Tuple{Float64}))
julia> close(s)
julia> # Text(String(take!(io))) # uncomment to show diff