Skip to content

Instantly share code, notes, and snippets.

@jackwillis
Created June 14, 2015 19:05
Show Gist options
  • Save jackwillis/c7d78a52cf697cda6e8a to your computer and use it in GitHub Desktop.
Save jackwillis/c7d78a52cf697cda6e8a to your computer and use it in GitHub Desktop.
# Better Kernel::system in Ruby
def sys(cmd)
*resp, status = `#{cmd}; echo -n "\n$?"`.lines
[resp.join.chomp, status.to_i]
end
sys("echo foo") #=> ["foo\n", 0]
sys("echo -n foo") #=> ["foo", 0]
sys("false") #=> ["", 1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment