5

当我尝试运行以下期望脚本时,它只是完成运行而不是等待用户输入。有人可以告诉我我做错了什么吗?

#!/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
4

2 回答 2

8

Expect 改变了 Tclgets命令,使其不等待标准输入;要在等待时读取一行,您需要这样做而不是gets stdin id

# Read input to stdin
expect_user -re "(.*)\n"
set id $expect_out(1,string)
于 2012-04-30T20:56:31.033 回答
0

试试这个代码:

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
于 2015-06-16T00:16:54.770 回答