Created
May 11, 2023 23:17
-
-
Save awfulcooking/fc9aad248fcc32b0f6e41f87fc0c2f84 to your computer and use it in GitHub Desktop.
This file contains 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 '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