Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #76668

Re: pexpect - logging input AND output

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.009
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'output': 0.05; 'matches': 0.07; 'assigning': 0.09; 'conf': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.11; "'w')": 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'stdlib.': 0.16; 'module': 0.19; 'input': 0.22; 'otherwise,': 0.22; 'this?': 0.23; 'header:User-Agent:1': 0.23; 'script': 0.25; 'logging': 0.26; 'header:X-Complaints-To:1': 0.27; 'tried': 0.27; 'correct': 0.29; "doesn't": 0.30; 'too.': 0.31; 'writes:': 0.31; 'figure': 0.32; 'running': 0.33; 'device': 0.34; "can't": 0.35; 'there': 0.35; 'possible': 0.36; 'should': 0.36; 'message- id:@gmail.com': 0.38; 'server': 0.38; 'to:addr:python-list': 0.38; 'little': 0.38; 'anything': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'commands': 0.60; 'is.': 0.60; 'email addr:gmail.com': 0.63; 'therefore': 0.72; 'initiates': 0.84; 'received:89': 0.85; 'device.': 0.93; 'subject:AND': 0.93
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Akira Li <4kir4.1i@gmail.com>
Subject Re: pexpect - logging input AND output
Date Wed, 20 Aug 2014 18:51:25 +0400
References <f6f7175a-37cc-44d0-9e62-b237f51d6ac8@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain
X-Gmane-NNTP-Posting-Host 89.169.229.68
User-Agent Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)
Cancel-Lock sha1:D9//dAOhwGyC+3HpR3v1lbVpYoM=
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.13212.1408546304.18130.python-list@python.org> (permalink)
Lines 50
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1408546304 news.xs4all.nl 2912 [2001:888:2000:d::a6]:45592
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:76668

Show key headers only | View raw


sj.constantine@gmail.com writes:

> i have a script running a few commands on a network device. i can't
> seem to figure out how to log both the input and output of what the
> pexpect script initiates and responds to.
>
> child = pexpect.spawn ('telnet '+ ip)
> child.expect ('.*:*')
> child.sendline (user)
> child.expect ('.*:*')
> child.sendline (password)
> child.expect(['.*#*', '.*>*'])
> child.sendline ('enable')
> child.expect (['Password:', '.*#*'])
> child.sendline (password)
> child.expect ('.*#*')
> child.sendline ('conf t')
> child.expect ('.*#*')
> child.sendline ('line vty 0 4')
>
> i have tried both these logging commands:
>
> child.logfile = open('log.txt', 'w')
> child.logfile=sys.stdout
>
> all i get is the input i send with expect/sendline combinations, i
> don't get any of what the device sends, only what i send the device:
>
> user
> password
> enable
> password
> conf t
> line vty 0 4
>
> any ideas of what is the correct way to go about this? just can't get the output!

To be clear, expect() doesn't send anything to the device. expect()
matches as little as possible therefore '.*:*' matches *nothing*.

If it is Python 3 then use pexpect.spawnu(). Otherwise, assigning to
child.logfile should work as is.

There is a telnetlib module in stdlib. x/84 python telnet server might
contain a client too.


--
Akira

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

pexpect - logging input AND output sj.constantine@gmail.com - 2014-08-14 01:59 -0700
  Re: pexpect - logging input AND output Chris Angelico <rosuav@gmail.com> - 2014-08-14 19:14 +1000
  Re: pexpect - logging input AND output Akira Li <4kir4.1i@gmail.com> - 2014-08-20 18:51 +0400

csiph-web