Assuming you don't want to do anything with the data, just read the first screen of data from less and then issue the 'q'.
(EDIT: This needed a tweak to give 'read' a size so that it didn't wait for the default size or eof)
#!/usr/bin/env python
import os, pexpect
class zz:
def __init__(self):
child = pexpect.spawn ('/home/usr/Desktop/b.sh')
# grab the first screen from 'less'
child.read(1)
child.send('q')
z = zz()
Here is the code I used for test:
~/tmp/reader$ cat a.py
#!/usr/bin/env python
import pexpect
try:
open('status.txt', 'w')
child = pexpect.spawn('/bin/sh "./b.sh"', timeout=10)
child.send('q')
child.expect(pexpect.EOF)
except Exception,e:
print 'exception'
print open('status.txt').read()
~/tmp/reader$ cat text.txt
iamtext
~/tmp/reader$ cat b.sh
#!/bin/sh
less text.txt
echo 'all done'
sleep 3
date > status.txt