В коде, вы использовали следующий код как puts
заявление
send "enter your password"
, который не является надлежащим образом. Обычно команда send
пытается отправить команды на консоль, и если какой-либо процесс будет создан с помощью скрипта, тогда эта команда будет отправлена на этот процесс.
В любом случае, вы получите инструкции, распечатанные в консоли. Но, помните об этом. Вместо этого лучше использовать команду send_user
.
Вы можете попробовать это
#!/usr/bin/expect
set server [lindex $argv 0]
stty -echo; #Disable echo. To avoid the password to get printed in the terminal
send_user "enter you password : "
# Using regex to grab all the input till user press 'Enter'
# Each submatch will be saved in the the expect_out buffer with the index of 'n,string'
# for the 'n'th submatch string
# expect_out(0,string) will have the whole expect match string including the newline
# The first submatch is nothing but the whole text without newline
# which is saved in the variable 'expect_out(1,string)
expect_user -re "(.*)\n" ;
stty echo; #Enable echo
set pwd $expect_out(1,string)
send $pwd\n;
expect "some-other-statment"
#Your further code here
Вы можете удалить stty -echo
и stty echo
, если вы не беспокоиться о пароле получение печататься в консоли
Ссылка: http://www.tcl.tk/man/expect5.31/expect.1.html
Спасибо дружище это работает хорошо. –