How to execute an expect scripts from windows

Closed
uma - Jan 6, 2009 at 03:29 AM
 yash - Jul 7, 2011 at 05:52 AM
Hello,
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
Related:

3 responses

neeks78 Posts 14 Registration date Wednesday September 24, 2008 Status Member Last seen May 12, 2009 1
Jan 6, 2009 at 04:11 AM
hi,
i was passing by when I noticed something which can help you.
it is the user's guide of how to use the expect script
try this link:
https://www.gidhome.com/ManHtml/tcl8.4.12/expect4win/expect.html
2
Hi Uma,

I too facing the same issue.If u got the answer can you forward to this mail Email Id removed for security

Thanks in Advance
N.kannan.
1
hi uma
u need to have
1.activestate tcl (preferably >8.5)
2.activestate expect
which I believe you already do
write your script and save it as a .tcl file
go to the directory where your script is stored in the command prompt
C:\usr\bin\path to your script>tclsh scriptname.tcl
this will execute your script

P.S. tclsh is a command line interpreter that executes tcl code.
1