Skip to content

Instantly share code, notes, and snippets.

@awfulcooking
Created May 11, 2023 23:17
Show Gist options
  • Save awfulcooking/fc9aad248fcc32b0f6e41f87fc0c2f84 to your computer and use it in GitHub Desktop.
Save awfulcooking/fc9aad248fcc32b0f6e41f87fc0c2f84 to your computer and use it in GitHub Desktop.
require 'pty'
module BackticksWithPty
def `(cmd)
output = ""
begin
PTY.spawn(cmd) do |stdout, stdin, pid|
for line in stdout
output << line
end
rescue Errno::EIO
# command exited normally, good news
end
rescue PTY::ChildExited => e
puts "The command exited with status #{e.status.exitstatus}"
end
output
end
end
Object.include BackticksWithPty
puts `ls --color`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment