lib/expectr.rb in expectr-0.8.4 vs lib/expectr.rb in expectr-0.9.0
- old
+ new
@@ -145,11 +145,10 @@
buf = ''
begin
@stdout.sysread(@buffer_size, buf)
rescue Errno::EIO #Application went away.
- Process.wait @pid
@pid = 0
break
end
buf.encode! "UTF-8"
@@ -160,10 +159,15 @@
@out_update = true
end
end
end
end
+
+ Thread.new do
+ Process.wait @pid
+ @pid = 0
+ end
end
#
# Clear output buffer
#
@@ -186,22 +190,22 @@
#
# Interrupts should be caught and sent to the application.
#
def interact
oldtrap = trap 'INT' do
- @stdin.syswrite "\C-c"
+ send "\C-c"
end
@flush_buffer = true
old_tty = `stty -g`
`stty -icanon min 1 time 0 -echo`
in_thread = Thread.new do
input = ''
while @pid > 0
if select([STDIN], nil, nil, 1)
- @stdin.syswrite STDIN.getc.chr
+ send STDIN.getc.chr
end
end
end
in_thread.join
@@ -212,11 +216,15 @@
#
# Send +str+ to application
#
def send(str)
+ begin
+ @stdin.syswrite str
+ rescue Errno::EIO #Application went away.
+ @pid = 0
+ end
raise ArgumentError unless @pid > 0
- @stdin.syswrite str
end
#
# === Synopsis
#