Expect commands not working in simple script

Posted by kelunn on 2011-04-22 11:14

Hello Folks,
I am new to AS Perl & Tcl. Most of my Perl has been in the Unix environment so I would "use Expect" right in my Perl program. Looks like this is not the way to do things in AS Perl for windows.
So now I am in the Win XP PRO environment, installed AS Perl 5.12.3 and Tcl
I am very confused on how to run and use Expect. I tried to write a simple script to ssh to a unix server and exit but got errors - can anyone provide guidance?
Tcl is installed at C:\Tcl\bin

my code for sshdemo.tcl:

package require Expect
puts "Hello - SSH demo!"
set thisPassw "Pass123"
exp_spawn "C:\Program Files\OpenSSH for Windows\bin\ssh.exe" -o StrictHostkeyChecking=no  user123@server25
expect -re "password: $" {exp_send "$thisPassw\r"}
expect -re "\$$" {exp_send "exit\r"}
exp_send_user "All done!"

This is what happens when I try to execute it:

tclplay>C:\Tcl\bin\tclsh.exe sshdemo.tcl
Hello - SSH demo!
invalid command name "exp_spawn"
    while executing
"exp_spawn "C:\Program Files\OpenSSH for Windows\bin\ssh.exe" -o StrictHostkeyChecking=no user123@server25"
    (file "sshdemo.tcl" line 5)