digidotcom / python-streamexpect

Python library providing cross-platform text matching for generic streams and sockets
Mozilla Public License 2.0
41 stars 8 forks source link

Add example of Popen to expect on a process #3

Open nastevens opened 8 years ago

nastevens commented 8 years ago

The following example was generated in a Reddit discussion and would make an excellent example for the repo:

import streamexpect
from subprocess import Popen, PIPE

pipe = Popen(r'net accounts', shell=True, stdout=PIPE).stdout

with streamexpect.wrap(pipe) as stream:
    match = stream.expect_regex(r'Computer role:\s+(\S+)')
    print('Computer role: ' + match.groups[0])
Hoohaha commented 1 year ago

Can you add this in examples?