Aiming Xu
2010-11-03
hi,
Nice to see you guys here.
what i am doing is all about 'interact' with expect.
A simple example that i used putty/securecrt login to A where the expect script lies on.
the script is simple , just telnet to another computer B and then interact so that i can do sth about B.
what i wanna do is type a command with long arguments, the argument so long that it would be printed in the next line.
at the very beginning, the expect script worked fine, but when i resized the terminal(putty/securecrt) window, sth interesting happened:I print a very long argument which would have to be shown in the next line, but when the character hit the end of the first line, it started form the beginning of the SAME line instead of next line, all the original characters lied at the beginning of the line were covered one by one with new typed characters.
its really, so i was wondering how does 'interact' affect terminal buffer, what happened inside 'interact' when i resized the window of the terminal.
or is there a way to solve this problem, so that when the character hit the end of the line it will start from next line no matter whether i resize the window or not.
any hlp would be appreciated.
Aimng
2010-11-03
ender
2010-11-03
Interact is supposed to just pass characters between the user and the spawned process.
It might be a problem with cooked mode vs raw mode.
Try interact -reset
Aiming Xu
2010-11-04
still doesn't work.
if i logged in directly with putty/securecrt there wasn't a problem.
but when it went through expect,strange things occurred.
code clip:
114 set user
115 set pwd1
116 set pwd2
117 if { $user != "" } {
118 spawn -noecho $ssh -l $user -p $port $ip
119 if { $pwd1 != "" } {
120 expect {
121 eof {puts "<ERROR:EOF>"}
122 timeout {puts "<ERROR:TIMEOUT>"}
123 "assword:" {
124 send "$pwd1\r"
125 if { $pwd2 != "" } {
126 expect {
127 eof {puts "<ERROR:EOF>"}
128 timeout {puts "<ERROR:TIMEOUT>"}
129 "]$ " {
130 send "su\r"
131 expect {
132 eof {puts "<ERROR:EOF>"}
133 timeout {puts "<ERROR:TIMEOUT>"}
134 "assword:" {
135 send "$pwd2\r"
136 }
137 }
138 }
139 }
140 }
141 }
142 }
143 }
144 } else {
145 spawn -noecho $ssh -p $port $ip
146 }
147 interact
148 exit 0
this is ssh login, but the problem is the same, very inelegant.will it be the problem with spawn? if it is, what can i do to get any hlp about it?
any hlp would be really appreciated.
Aiming
ender
2010-11-05
I tried on my system and can't duplicate it using putty and ssh into another system. So the only things I can think of are
try without the -noecho
Maybe it's the terminal settings on the server you're ssh'ing into that is causing problems.
Get the book exploring expect which has a lot of information on the options for spawn and interact plus details on how it works
Or maybe not use expect for this. Since you're using ssh why not use keys so you can skip the login process.
Sorry couldn't help more. Good luck.
Aiming Xu
2010-11-08
I didn't deal with the signal SIGWINCH.
now add:
trap {
set rows
set cols
stty rows $rows columns $cols < $spawn_out(slave, name)
}WINCH
It works now LOL.
Thank you ender21014, god luck to you.
Aiming
ender
2010-11-08
Excellent. Thank you for the information on making it work.