> On May 10, 1:15 am, tkhdri
@gmail.com wrote:
> > 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 :
> > (
> 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.
woops just noticed I put too many \\ in there