I am trying to make a generator for reading a list of `files’, where a file may be an actual file or a subprocess. For the interface it is nice if the result can be a file descriptor, as the interpretation of the content depends on the caller.
I make the generator with
push!() and the subprocess using
`` is a single backtick but I don’t know how to enter this in here].
The problem is that the subprocess’s file descriptor produces 0 bytes when read from by the caller. The problem is maybe best demonstrated by the following code:
genpipe(file, pipe=false) = Channel() do c for i in 1:2 if pipe fd, process = open(`cat $file`, "r") else fd = open(file, "r") end push!(c, fd) close(fd) end end open("out.txt", "w") do fd println(fd, "Hello, pipe") end for pipe in [false, true] for fd in genpipe("out.txt", pipe) println("pipe ", pipe, " len ", length(read(fd))) end end
pipe false len 12 pipe false len 12 pipe true len 0 pipe true len 0
The last two lines are unexpected.
I’ve also tried the
open() do fd construct within the generator, but this gives the same result.