How to execute an expect scripts from windows
Last answer on Apr 8, 2009 12:15:27 pm BST uma, on Jan 6, 2009 8:29:57 am GMTHello,
It might sound silly to ask this question.but i am using this expect scripts for the first time.
so let me know how to execute an expect script.
i was tring to execute a script below.
set hostname "10.65.201.35"
set username "ftp"
set password "test123"
set target_directory "C:\expect_progs"
set build_directory "C:\Inetpub\ftproot"
set build_file "success.doc"
# 1. Set the ftp prompt using a regular expression.
set ftp_prompt "ftp>?"
# 2. Print to console.
puts stdout "Connecting to $hostname to upload the latest build."
# 3. Connect to the FTP server using the "spawn" command.
spawn ftp $hostname
# 4. Wait for a login prompt.
expect -re "(Name|login|Login|Username).*:.*" {
# 5. Login prompt received. Send user name to Unix server.
exp_send "$username\r"
exp_send_user "sent username\n"
} eof {
# 6. No login prompt received. Display an error.
exp_send_user "could not connect\n"
}
# 7. Wait for a password prompt from the Unix server.
expect "Password:" {
# 8. Password prompt received. Send the password.
exp_send "$password\r"
}
# 9. Wait for an FTP prompt. Enter FTP commands.
expect -re $ftp_prompt {
# 10. Change to the upload directory on the Unix server.
exp_send "cd $target_directory\r"
}
expect -re $ftp_prompt {
# 11. Change to the local directory you want to
# upload from (Windows machine).
exp_send "lcd $build_directory\r"
}
expect -re $ftp_prompt {
# 12. Upload the file to the Unix server.
exp_send "put $build_file\r"
}
expect -re $ftp_prompt {
# 13. Close the FTP connection to the Unix server.
exp_send "exit\r"
}
i executed this script as
tclsh filename.exp
but it was throughing and error as below.
Connecting to 10.65.201.35 to upload the latest build.
invalid command name "spawn"
while executing
"spawn ftp $hostname"
(file "file.exp" line 18)
child process exited abnormally
%
i was using the tclsh84 to execute this script.
kindly help me out and let me know were i am going wrong.
Thanks in advance!!!!
Uma
Hi,
|

