Tcl 获取未在expect脚本中等待用户输入的内容

Tcl 获取未在expect脚本中等待用户输入的内容,tcl,user-input,expect,Tcl,User Input,Expect,当我尝试运行下面的expect脚本时,它只是完成运行,而不是等待用户输入。有人能告诉我我做错了什么吗 #!/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修改Tclget命令,使其不等待标准输入;要在等待时读取一行,

当我尝试运行下面的expect脚本时,它只是完成运行,而不是等待用户输入。有人能告诉我我做错了什么吗

#!/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修改Tcl
get
命令,使其不等待标准输入;要在等待时读取一行,您需要这样做,而不是
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

注意:我在expect文档中找到了如何从用户那里获取输入,并通过测试确认expect更改了
gets stdin的阻塞行为。我对这种变化感到非常惊讶。