Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

TCL(Tool Command Language) Scripting

Buffer problem with Expect when telneting from one Windows machine to another?


Hi all.  I'm running the latest ActiveTcl/Expect package on a Windows
XP Pro machine and using Expect to telnet to another Windows XP Pro
machine.

I can telnet in and login just fine.  At that point, I see a windows
command line prompt, such as "C:\>" or something similar.

I want to then run a command on the remote machine and capture the
results in my script.  For example, I would like to run "Dir" and get
the results back so that I can dump them to a file on the local
machine.

So my code looks something like this (after the login has completed)

....
set timeout 10
set mainPrompt "\[a-zA-Z\]:\\\\.*>"

send -i $sid "dir\r"

#after 1000

expect -i $sid timeout {
    exit 5    #did not get back to prompt

} eof {

    exit 99  #lost connection to host

} -re $prompt

set result "$expect_out(buffer)"
....

Now if I don't uncomment the "after 1000" statement, there is next to
nothing in the buffer.
If I do uncomment the "after 1000", I get more of what I expect in the
buffer, but instead of seeing something like this:

C:\test>dir
 Volume in drive C has no label.
 Volume Serial Number is 0C6B-4D45

 Directory of C:\test

05/10/2007  02:08 AM    <DIR>          .
05/10/2007  02:08 AM    <DIR>          ..
05/10/2007  02:08 AM                 4 four.txt
05/10/2007  02:08 AM                 4 one.txt
05/10/2007  02:08 AM                 4 three.txt
05/10/2007  02:08 AM                 4 two.txt
               4 File(s)             16 bytes
               2 Dir(s)  22,074,261,504 bytes free

C:\test>

I get a mangled up buffer like this:

C:\test>dirVolume in drive C has no label.Volume Serial Number is
0C6B-4D45Direc
tory of C:\test

05/10/2007  02:10 AM    <DIR>          .
05/10/2007  02:10 AM    <DIR>          ..
05/10/2007  02:10 AM                 4 four.txt
05/10/2007  02:10 AM                 4 one.txt
05/10/2007  02:10 AM                 4 three.txt
05/10/2007  02:10 AM                 4 two.txt4 File(s)             16
bytes2 Dir(s)  22,073,372,672 bytes free

C:\test>

Does anyone know why this happens?  It's doesn't feel like a timing
issues because I've tried tons of changes to timing, but I
consistently get the same mangled result back.  Any help is
appreciated.  After trying to figure this problem out for the last 10
hours, I'm going to sleep and I'll be back up in 4 hours to try again :
(

On May 10, 2:15 pm, tkhdri@gmail.com wrote:

> <snip>
> set timeout 10
> set mainPrompt "\[a-zA-Z\]:\\\\.*>"

I don't really have the answer to your mangled buffer problem but may
I suggest that this:

  set mainPrompt {[a-zA-Z]:\\.*>}

is much more readable.

On May 10, 3:38 am, "slebet@yahoo.com" <slebet@gmail.com> wrote:

> I don't really have the answer to your mangled buffer problem but may
> I suggest that this:

>   set mainPrompt {[a-zA-Z]:\\.*>}

> is much more readable.

Thanks, that does look much better
On May 10, 1:15 am, tkhdri@gmail.com wrote:

The reason you get different results when the after 1000 is commented
or uncommented is because
in the case where you do have a delay the expect_out buffer fills and
you match the last prompt ( your regular epression for prompt is
greedy because of the .* and will match as much as it can. When you do
not delay then you will get a smaller match.  You need a better regexp
for your prompt such as
set prompt {^[a-zA-Z]:\\[^>]*>}
the [^>] means any character but > so it matches C:\a> but not
"C:\a>
the raint in spain> "
which yours does.

Carl
when you have not delayed.

On May 10, 6:20 pm, Bezoar <cwjo@gmail.com> wrote:

woops just noticed I put too many \\ in there
should be set prompt {^[a-zA-Z]:\[^>]*>}
Carl
Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc