Created
April 3, 2022 12:57
-
-
Save searls/14afa5dffac392550f8c7e386f81a850 to your computer and use it in GitHub Desktop.
Silly little class for when you want the combined stdout/stderr output of a command and its success status
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 "open3" | |
class ExecutesCommand | |
Result = Struct.new(:success, :output, keyword_init: true) | |
def call(command) | |
stdin, stdout_and_stderr, wait_thr = Open3.popen2e(command) | |
result = Result.new( | |
success: wait_thr.value == 0, | |
output: stdout_and_stderr.read | |
) | |
stdin.close | |
stdout_and_stderr.close | |
result | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment