Skip to content

Instantly share code, notes, and snippets.

@julik
Created April 14, 2010 16:06
Show Gist options
  • Save julik/365993 to your computer and use it in GitHub Desktop.
Save julik/365993 to your computer and use it in GitHub Desktop.
def cli(argv)
old_stdout, old_stderr, old_argv = $stdout, $stderr, ARGV.dup
os, es = StringIO.new, StringIO.new
begin
$stdout, $stderr = os, es
ARGV.replace(argv.split)
load(BIN_P)
return [0, os.string, es.string]
rescue Exception => boom # The binary uses exit(), we use that to preserve the output code
return [boom.status, os.string, es.string] if boom.is_a?(SystemExit)
raise boom
ensure
ARGV.replace(old_argv)
$stdout, $stderr = old_stdout, old_stderr
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment