Expect for Windows


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Expect for Windows
# 1  
Old 01-01-2008
Expect for Windows

To All,

I have installed ActiveState Active Tcl 8.4.16.0, I have a need for Expect on Windows, whereas, it is close to Epect/UX, it has differences. I am having trouble with the following command:

# set X [exec /usr/bin/grep a /tmp/FAIL] this works well in Expect/UX

trying the same command in Expect/Windows, I get the following fail:
"could not execute no such file or directory /usr/bin/grep".

Any help will be aprreciated,

Thanks,

Dave
# 2  
Old 01-02-2008
Dave, you're trying to use the "grep" binary, which is not available for Windows, plus the paths in Windows are usually like "d:\folder\program.exe" i.e. using backslashes.
# 3  
Old 01-02-2008
If you don't want to use an external 'grep' binary a rudimentary workalike is only a few lines in tcl which can be easily utilized by your expect script.
Code:
proc grep {pat fname} {

                         if {[catch {set fd [open $fname r]} op_err]} { 
                             puts "Error: $op_err"
                             return 1
                         }
                         while {[gets $fd line] > 0} {
                                if {[regexp $pat $line]} {puts $line}
                         }
                         close $fd
                         return 0
}

Code:
example:
foreach x [glob Documents/*txt] {
                         grep "^\[a-zA-Z\]{9}\[\t \]\[^0-9\].*$" $x
}

# 4  
Old 01-04-2008
grep for Windows

I guess it's my fault for not being clear, I am executing expect from Windows, but the grep command is being done on a UX machine.
The first thing the code does is telnet to a UX machine, then I find
that the grep command does not work.

Dave
# 5  
Old 01-04-2008
You are trying to exec a local grep binary that does not exist. The exec command you are using executes on the local machine, not on the remote machine. in order to get the output of a grep on the remote host try something like (untested) :

Code:
set prompt "(\n.*# | .*> | .*\$)" 
set searchstr [lindex $argv 2]
set rfilename [lindex $argv 3]

expect {

           -re $prompt {
                           send "grep $searchstr $rfilename\r\n"
                           expect -re "\n(.*)\n$prompt" {
                                                                    send_user "\n$expect_out(buffer),$expect_out(1,string)\n"
                                                                    close $spawn_id
                                                                     wait $spawn_id
                           }
             }
}

# 6  
Old 01-04-2008
Bug

Thanks Thanks
# 7  
Old 01-10-2008
Set X from grep

Ramen,

I have been away for the past couple of days, your answer helped with some other problems I was having with syntax, however I could always get grep to work, the original problem I was having, and hopefully you can help was setting a varaiable with the output of grep. This works with UX

set X [exec /usr/bin/grep a /tmp/FAIL] this works well in Expect/UX and this works with Windows/Expect:
expect {#*} {send "/usr/bin/grep -i scsi* /var/adm/syslog/syslog.log >> /tmp/fail.txt\n\r"}

The problem is trying to set the variable X within Windows/Expect? Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. Programming

Expect script returning string following a found expect.

I'm fairly new to scripting so this might not be possible. I am using Expect with Cisco switches and need to capture the string after finding the expect request. For example, when I issue "show version" on a Nexus switch, I'm looking to capture the current firmware version: #show version ... (0 Replies)
Discussion started by: IBGaryA
0 Replies

2. Programming

Calling expect script inside another expect

Hi, Am very new to expect scripting.. Can You please suggest me how to call an expect script inside another expect script.. I tried with spawn /usr/bin/ksh send "expect main.exp\r" expect $root_prompt and spawn /usr/bin/ksh send "main.exp\r" expect $root_prompt Both... (1 Reply)
Discussion started by: Priya Amaresh
1 Replies

3. Shell Programming and Scripting

Expect - Comparison of expect value and loop selection

Hello All, I am trying to automate an installation process using expect and sh script. My problem is that during the installation process the expected value can change according to the situation. For Example if this is a first time installation then at step 3 I'll get "Do you want to accept... (0 Replies)
Discussion started by: alokrm
0 Replies

4. Shell Programming and Scripting

Need help with Expect script for Cisco IPS Sensors, Expect sleep and quoting

This Expect script provides expect with a list of IP addresses to Cisco IPS sensors and commands to configure Cisco IPS sensors. The user, password, IP addresses, prompt regex, etc. have been anonymized. In general this script will log into the sensors and send commands successfully but there are... (1 Reply)
Discussion started by: genewolfe
1 Replies

5. Shell Programming and Scripting

strange expect script behavior, or am i misunderstanding expect scripting?

Hello to all...this is my first post (so please go easy). :) I feel pretty solid at expect scripting, but I'm running into an issue that I'm not able to wrap my head around. I wrote a script that is a little advanced for logging into a remote Linux machine and changing text in a file using sed.... (2 Replies)
Discussion started by: v1k0d3n
2 Replies

6. Shell Programming and Scripting

Windows expect

I am using ActiveState 8.4.16.0, I have found this code format that seems to work great: expect "Login:*" send "root\r" expect ">*" send "ksh\r" expect "#*" send "tar -xvf /dev/rmt/0m\r" expect "#" My question is, how do I set it up to fail out if one of the expect calls doesn't... (0 Replies)
Discussion started by: dave_m
0 Replies
Login or Register to Ask a Question