Skip to content

Instantly share code, notes, and snippets.

@NeoCat
Created January 13, 2011 04:52
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save NeoCat/777418 to your computer and use it in GitHub Desktop.
pty-relay.rb
#!/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
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