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

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.

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.

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
}
example:
foreach x [glob Documents/*txt] {
                         grep "^\[a-zA-Z\]{9}\[\t \]\[^0-9\].*$" $x
}

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

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) :

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
                           }
             }
}

Thanks Thanks

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? :confused:

Sorry..I haven't checked back on this thread. If you have more details and this is still a problem I'll try to help.

I've been stuck on this one for awhile.. I am ussing ActiveState tcl 8.4.16.0, I am executing an expect script from windows that telnets to
an HPUX box, this part works well, then I try to grep Info from a file
and set a variable with the info. Simple in UX, not so simple from a PC..
I can tell from the history file on the HPUX box that the grep
portion is working, but it is not setting the variable, here is the line of code.

set X [send "grep test /tmp/testfile\r\n"]

I'm expecting X to be set with the grep'd value of test from the /tmp/testfile. I'm seeing the grep function work, but the variable is not getting set? Is the variable not being exported to the HPUX machine?
Any help will be gretly appreciated.

Dave
:confused: