Skip to content

Instantly share code, notes, and snippets.

@searls
Created April 3, 2022 12:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save searls/14afa5dffac392550f8c7e386f81a850 to your computer and use it in GitHub Desktop.
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
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