Created
August 2, 2025 19:20
-
-
Save havenwood/dd2db6206b523cbafa8b5f2457e84a16 to your computer and use it in GitHub Desktop.
Example io-stream for #ruby IRC
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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