After playing with this, it seems the key is to pass objects to the ANSI terminal via the following:<div><br></div><div><div><span class="Apple-style-span" style="font-family: 'courier new', monospace;">import ANSI</span></div>
<div><span class="Apple-style-span" style="font-family: 'courier new', monospace;"><br></span></div><div><span class="Apple-style-span" style="font-family: 'courier new', monospace;">crt = ANSI.ANSI(25,80)</span></div>
<div><span class="Apple-style-span" style="font-family: 'courier new', monospace;"><br></span></div><div><span class="Apple-style-span" style="font-family: 'courier new', monospace;">head_output = ["line 1 ABCDEFGHIJKL", "line 2 ABCDEFGHIJKL",</span></div>
<div><span class="Apple-style-span" style="font-family: 'courier new', monospace;">               "line 3 ABCDEFGHIJKL", "line 4 ABCDEFGHIJKL",</span></div><div><span class="Apple-style-span" style="font-family: 'courier new', monospace;">               "line 5 ABCDEFGHIJKL", "line 6 ABCDEFGHIJKL"]</span></div>
<div><span class="Apple-style-span" style="font-family: 'courier new', monospace;"><br></span></div><div><span class="Apple-style-span" style="font-family: 'courier new', monospace;">for i in head_output:</span></div>
<div><span class="Apple-style-span" style="font-family: 'courier new', monospace;">  crt.write(i + "\n") </span></div><div><span class="Apple-style-span" style="font-family: 'courier new', monospace;"><br>
</span></div><div><span class="Apple-style-span" style="font-family: 'courier new', monospace;">print crt.get_region(2, 6, 5, 10)</span><br></div><div><br></div><div>Output from ANSI terminal region:</div><div>['2 ABC', '3 ABC', '4 ABC', '5 ABC']<br>
</div><div><br></div><div class="gmail_quote">On Sun, Nov 2, 2008 at 3:30 PM, Henry Chang <span dir="ltr"><<a href="mailto:goldspin@gmail.com">goldspin@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div>I am taking a step back, and just get something simple working with ANSI.  The following code works (creates the ANSI terminal object, and inserts a few characters, and scrap the characters back).</div><div><br></div>

<div><div><span>import ANSI</span></div><div><span><br></span></div>
<div><span>crt = ANSI.ANSI(25,80)</span></div><div><span><br>
</span></div><div><span>crt.insert_abs(2,2,"a")</span></div><div><span>crt.insert_abs(3,10,"b")</span></div>
<div><span>crt.insert_abs(5,5,"z")</span></div><div><span><br>
</span></div><div><span>print crt.get_region(1, 1, 5, 10)</span><br></div><div><br></div><div>But if I try to print something to the screen, the ANSI terminal doesn't capture anything.</div>
<div><br></div><div><div><span>import ANSI</span></div><div><span>import os</span></div>
<div><span><br></span></div><div><span>crt = ANSI.ANSI(25,80)</span></div>
<div><span><br></span></div><div><span>crt.insert_abs(2,2,"a")</span></div>
<div><span>crt.insert_abs(3,10,"b")</span></div><div><span>crt.insert_abs(5,5,"z")</span></div>
<div><span><br></span></div><div><span>head_output = os.system("head -n 10 long_text_file.txt")</span></div>
<div><span>print head_output</span></div><div><span><br></span></div>
<div><span style="font-size:12px">print crt.get_region(1, 1, 5, 10)</span><br></div></div><div><br></div><div>How can I get the head output into the ANSI terminal?  My example code is similar to the the usage example from the link below.  Yet ANSI is not scraping the screen.  What am I doing wrong?</div>

</div><div><br></div><div><a href="http://coding.derkeiler.com/Archive/Python/comp.lang.python/2005-03/1441.html" target="_blank">http://coding.derkeiler.com/Archive/Python/comp.lang.python/2005-03/1441.html</a><br><br></div>
<div>Thanks for any help.</div><div><div></div><div class="Wj3C7c">
<div><br><div class="gmail_quote">On Sat, Nov 1, 2008 at 5:03 PM, Henry Chang <span dir="ltr"><<a href="mailto:goldspin@gmail.com" target="_blank">goldspin@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

Using the below script, I can use pexpect to correctly output the entire remote terminal content to screen.  <div><br></div><div>At this point, I am running into difficulty to scrap the screen, for the screen elements that I want.  (Say: the screen region from the complete 3rd line to the 8th line.)  I believe I need to use ANSI module.  I tried a few things, but have run out of ideas.  </div>


<div><div><br></div><div>Can anyone please help?  How can the code below be modified to use ANSI?</div><div><br></div><div>Thanks so much for any help.<br><div><br></div><div><br></div><div><div>import pexpect<br></div><div>


<br></div><div>child = pexpect.spawn ('ssh dummy_user@dummy_ip')</div><div>child.expect ('Password: ')</div><div><br></div><div>child.sendline ('dummy_password')</div><div>child.expect ('[513] ')</div>


<div><br></div><div>child.sendline ('w2ktt')  # windows 2000 terminal type</div><div>child.expect ('Command:')</div><div><br></div><div>child.sendline ('dummy_command')</div><div>child.expect('non-guest room')</div>


<div><br></div><div># This will output the console to the screen.</div><div>print child.before</div><div><br></div><div>child.expect('Command:')</div><div>child.sendline ('logoff')</div><div><br></div></div>


</div></div>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div>