Skip to content

Instantly share code, notes, and snippets.

@havenwood
Created August 2, 2025 19:20
Show Gist options
  • Save havenwood/dd2db6206b523cbafa8b5f2457e84a16 to your computer and use it in GitHub Desktop.
Save havenwood/dd2db6206b523cbafa8b5f2457e84a16 to your computer and use it in GitHub Desktop.
Example io-stream for #ruby IRC
require 'io/stream'
require 'open3'
module Command
Result = Data.define(:out, :err, :status)
def self.run(*, **)
Open3.popen3(*, **) do |stdin, stdout, stderr, thread|
stdin.close
Result.new(
out: IO::Stream::Buffered.wrap(stdout).read,
err: IO::Stream::Buffered.wrap(stderr).read,
status: thread.value
)
end
end
end
Command.run('ls', '-la', '/tmp')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment