>>>
#!/usr/local/bin/expect -f
spawn $argv
expect "foo"
send "bar\r"
...
<<<
The goal is to be able to pass in to blah.tcl, the name of a
program/script to spawn along with all its arguments. Like this:
>>>
$ blah.tcl ftp xxx.xxx.xxx.xxx
<<<
But, when I try this, I get the following error:
>>>
couldn't execute "ftp xxx.xxx.xxx.xxx": no such file or directory
while executing
<<<
I looks like spawn is treating the whole string "ftp xxx.xxx.xxx.xxx" as
a single program name rather than a program name with an argument. I
can make this work by separating the arguments in the spawn call:
>>>
spawn [lrange $argv 0 0] [lrange $argv 1 1]
<<<
But, this only works for a program name with one argument. How do I
make this work with an arbitrary number of arguments?
I am using expect version 5.32.1.
Thanks!
John
eval spawn $argv
> spawn [lrange $argv 0 0] [lrange $argv 1 1]
FYI, [lindex $argv 0] is probably slightly more efficient than
[lrange $argv 0 0]
Further off topic, a common Tcl idiom (until 8.5) to assign the values
of a list to a set of variables is:
foreach {firstvar secondvar thirdvar} $list break
--
Glenn Jackman
"You can only be young once. But you can always be immature." -- Dave Barry
Not to mention the fact that lrange returns a list and lindex returns a
single value, and a list of one element won't necessarily have the same
string representation as just the element itself.
It's probably a moot point for the types of data likely to be used by
the original poster, but code using lrange in this manner certainly can
fail for certain types of data.
--
Bryan Oakley
http://www.tclscripting.com
>>>
eval spawn $argv
<<<
And thanks for the lindex tip, too. Thanks for the help!
John
if 1 [linsert $argv 0 spawn ]
uwe