Handle character echoing sessions more gracefully

git-svn-id: file:///home/svn/framework3/trunk@11268 4d416f70-5f16-0410-b530-b9f4589650da
unstable
HD Moore 2010-12-09 22:44:17 +00:00
parent 493db14006
commit fa29afaece
1 changed files with 11 additions and 5 deletions

View File

@ -118,13 +118,19 @@ class CommandShell
# Send the command to the session's stdin.
shell_write(cmd + "\n")
# wait up to 5 seconds for some data to appear
if (not (::IO.select([rstream], nil, nil, 5)))
return nil
timeo = 5
etime = Time.now.to_f + timeo
buff = ""
# Keep reading data until no more data is available or the timeout is
# reached.
while (Time.now.to_f < etime and ::IO.select([rstream], nil, nil, timeo))
res = shell_read(-1, 0.01)
buff << res if res
timeo = etime - Time.now.to_f
end
# get the output that we have ready
shell_read(-1, 0.01)
buff
end