2

私は今日、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 コマンドで作成した他のスクリプトは正常に動作するようですか?

4

1 に答える 1

1

問題

主な問題は、コマンドを適切に分離していないことです。TCL のコマンドは、改行またはセミコロンで区切る必要があります。

解決

一般に、適切な形式の複合ステートメントがない限り、Expect または TCL コマンドは 1 行に 1 つだけにする必要があります。たとえば、次の改訂されたスニペットは機能します。

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

于 2012-06-26T06:03:17.613 に答える