Arguments to your Expect script are in the global array $argc. Grabbing an old Expect script, here is a sample of how you can manually process command-line arguments:
set i 0
while {$i < $argc} {
if ![string compare "-m" [lindex $argv $i]] {
incr i
if $i==$argc {
send_user "-m specified without machine, FAILING"
exit -3
}
set machine [lindex $argv $i]
} elseif ![string compare "-n" [lindex $argv $i]] {
incr i
if $i==$argc {
send_user "-n specified without name, FAILING"
exit -3
}
set name [lindex $argv $i]
} elseif ![string compare "-p" [lindex $argv $i]] {
incr i
if $i==$argc {
send_user "-p specified without password, FAILING"
exit -3
}
set password [lindex $argv $i]
} elseif ![string compare "-c" [lindex $argv $i]] {
incr i
if $i==$argc {
send_user "-c specified without argument, FAILING"
exit -3
}
set cmd [lindex $argv $i]
}
incr i
}
Now Perl can pass things on the command line. I don't know enough TCL to know if there is a cleaner way to do this processing (I would *hope* that there is). But it works.
Incidentally I would suggest that before hand-rolling a lot of Expect scripts that you look to CPAN for modules to drive the same things. For instance try Net::Telnet or failing that, Expect. Then you don't need to mix languages and error handling will probably be a bit easier as a result... |