Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Expect while loop

2,335 views
Skip to first unread message

brian...@nextel.com

unread,
Aug 31, 2000, 1:21:37 AM8/31/00
to
Does anyone know why I would get an error on this while loop? I took it
word for word from the Expect book. I'm trying to read a file line by
line and send each line as a command until the end of the file is
reached.

set fp [open sublist.txt]

while {[gets $fp line] != -1}
{
send "$line\r"
sleep 1
}
close $fp

------------

and here is the error I get:

wrong # args: should be "while test command"
while compiling
"while {[gets $fp line] != -1}"
(file "./dap_fleets.exp" line 45)

-------------

Any ideas?

Thanks,

-Brian


Sent via Deja.com http://www.deja.com/
Before you buy.

Cameron Laird

unread,
Aug 31, 2000, 1:49:01 AM8/31/00
to
In article <8okq0j$cq0$1...@nnrp1.deja.com>, <brian...@nextel.com> wrote:
>Does anyone know why I would get an error on this while loop? I took it
>word for word from the Expect book. I'm trying to read a file line by
>line and send each line as a command until the end of the file is
>reached.
>
>set fp [open sublist.txt]
>
>while {[gets $fp line] != -1}
> {
.
.
.
Change

while {[gets $fp line] != -1}
{
...
to

while {[gets $fp line] != -1} {
...

'Ts instructive how variable even "word for word" can be, eh?
--

Cameron Laird <cla...@NeoSoft.com>
Business: http://www.Phaseit.net
Personal: http://starbase.neosoft.com/~claird/home.html

Darren New

unread,
Aug 31, 2000, 1:55:37 AM8/31/00
to
brian...@nextel.com wrote:
>
> Does anyone know why I would get an error on this while loop? I took it
> while {[gets $fp line] != -1}
> {

The { has to be on the same line as the while, due to Tcl's syntax.

while {[gets $fp line] != -1} {

send ...
}

Otherwise, "while" thinks you only gave it the test and not the command.
Hence,

> wrong # args: should be "while test command"

--
Darren New / Senior MTS & Free Radical / Invisible Worlds Inc.
San Diego, CA, USA (PST). Cryptokeys on demand.
"No wonder it tastes funny.
I forgot to put the mint sauce on the tentacles."

0 new messages