运行我的Expect脚本时为什么会出现“未找到命令”?

时间:2012-06-25 22:59:28

标签: tcl expect

我今天一直在玩Expect / TCL,我希望有人能告诉我为什么下面的脚本失败了:

: command not found  
./expect3: line 3: send: command not found

#!/usr/bin/expect -f

send " we are going to open up a file for reading, ok? \n"
expect "ok"

set fileopen [open "/home/aaron/text.txt" "r"]

set a [read $fileopen]
send "i am expecting to see a string from the file here $fileopen"

close $fileopen

send和close命令都失败了,但是我用spawn命令编写的其他脚本似乎工作正常吗?

1 个答案:

答案 0 :(得分:1)

问题

主要问题是您没有正确分离命令。 TCL中的命令必须用换行符或分号分隔。

解决方案

通常,每行只应有一个Expect或TCL命令,除非你有一个格式正确的复合语句。例如,此修订后的代码段将起作用:

#!/usr/bin/expect -f

send "We are going to open up a file for reading, ok?\n"
expect "ok"

因为send和expect命令由换行符分隔。

另请参阅

http://tmml.sourceforge.net/doc/tcl/Tcl.html