当我尝试运行以下期望脚本时,它只是完成运行而不是等待用户输入。有人可以告诉我我做错了什么吗?
#!/usr/bin/expect
puts -nonewline stdout "Enter device id:"
flush stdout
gets stdin id
puts -nonewline stdout "Enter device name:"
flush stdout
gets stdin name
当我尝试运行以下期望脚本时,它只是完成运行而不是等待用户输入。有人可以告诉我我做错了什么吗?
#!/usr/bin/expect
puts -nonewline stdout "Enter device id:"
flush stdout
gets stdin id
puts -nonewline stdout "Enter device name:"
flush stdout
gets stdin name
Expect 改变了 Tclgets
命令,使其不等待标准输入;要在等待时读取一行,您需要这样做而不是gets stdin id
:
# Read input to stdin
expect_user -re "(.*)\n"
set id $expect_out(1,string)
试试这个代码:
expect "\\$"
puts -nonewline "please enter a swithch user: "
flush stdout
set userName [gets stdin]
puts $userName
expect "\\$" ;# without this line, the script would exit too fast
;# for the "echo hello" to be sent to stdout by bash
;# and thus wont be recorded