5

次の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
4

2 に答える 2

8

Expectはgets、標準入力を待たないようにTclコマンドを変更します。それを待っている間に行を読むには、次の代わりにこれを行う必要があります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 に答える