pty-relay.rb
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
#!/usr/bin/ruby | |
require 'pty' | |
Signal.trap(:CHLD, 'IGNORE') | |
system "stty raw -echo 2> /dev/null" | |
p = PTY.spawn '/bin/sh' | |
until p[0].closed? || STDIN.closed? | |
s = IO.select [p[0], STDIN] | |
while s0 = s[0][0] | |
s[0].shift | |
if s0 === STDIN then out = p[1] else out = STDOUT end | |
begin | |
out.write s0.readpartial(4096) | |
out.flush | |
rescue | |
p $! | |
p[0].close | |
p[1].close | |
system "stty -raw 2> /dev/null" | |
puts | |
exit | |
end | |
end | |
end |
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
server side: nc -l 12345 < fifo | ./test.rb > fifo | |
client side: stty raw -echo; nc localhost 12345 ; stty -raw |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment