1require 'pty' 2 3if ARGV.size == 0 then 4 ofile = "typescript" 5else 6 ofile = ARGV[0] 7end 8 9logfile = File.open(ofile,"a") 10 11system "stty -echo raw lnext ^_" 12 13PTY.spawn("/bin/csh") do |r_pty,w_pty,pid| 14 15 Thread.new do 16 while true 17 w_pty.print STDIN.getc.chr 18 w_pty.flush 19 end 20 end 21 22 begin 23 while true 24 c = r_pty.sysread(512) 25 break if c.nil? 26 print c 27 STDOUT.flush 28 logfile.print c 29 end 30 rescue 31 # print $@,':',$!,"\n" 32 logfile.close 33 end 34end 35 36system "stty echo -raw lnext ^v" 37 38