Hi!
Thank you for the thoughtful post. We never take these comments as negative, we know there is still a lot to improve.
I’ll go section by section:
Process
It would be really nice if you could show your current code. From your description of the problem:
I was a bit hung up on trying to tee the contents of stdout & stderr (show in foreground and have access to it after completion) and get the exit code at the end
So it seems you want to output to STDOUT but also have the contents later. We can use IO::MultiWriter for that: write to STDOUT and to a separate IO::Memory
which we can consume later:
output = IO::Memory.new
multi_output = IO::MultiWriter.new(STDOUT, output)
Process.run("ls", output: multi_output)
puts
puts "Above was output from the process, but here it goes again!"
puts output.to_s
(Process.run
returns the status so you have that too)
But maybe you want to send it to STDOUT and to something that you can receive input from. That’s what IO.pipe is for.
read, write = IO.pipe
multi_output = IO::MultiWriter.new(STDOUT, write)
spawn do
while line = read.gets
puts "Got line!: #{line}"
end
end
Process.run("ls", ["-la"], output: multi_output)
In the above snippet we probably don’t need multi output because we can already output from the read
end of the pipe.
But I guess it all depends on what exactly you want to accomplish. We can try to find a way to do it and see if the existing API can solve it in a nice way.
What I know is that we are probably missing some examples in Process
, or in general there’s a missing tutorial for it.
IO
Does the current IO implementation - or child implementations, like
File
- provide a way to ‘stream’ (lazy-load) at a high level?
What do you mean by streaming?
Methods like
.each_line
would be a great candidate, or perhaps another abstraction that provides aStream
object which acts like a generator instead of loading in the entire contents into memory.
What is a generator? The concept of generator exists in multiple languages with different meanings.
Maybe showing what code you have in mind would help me understand this.
Path
Path is a very recent addition to the standard library. That’s why it’s not available in many methods yet.