3

I'd like to write a wrapper for an interactive CLI Program (the Asterisk CLI).

Basically, I need to keep the interaction with the CLI (including tab-completion) but I want to filter the output of Asterisk, in order to show only lines matching a given pattern.

I tried a select() based approach, using popen.popen4 and putting asterisk stdout_and_stderr and sys.stdin in the read_fs, but it sort of didn't work.

Can anyone give some good pointers to me?

Thanks a lot, Andrea

1
  • "sort of didn't work". That's not helpful. What didn't work? What problem did you have? If you want a specific answer, please ask a specific question. With details. Commented Oct 17, 2009 at 12:09

2 Answers 2

6

Pexpect might be useful for you: http://sourceforge.net/projects/pexpect/

Description from the webpage: "Pexpect is a Python module for spawning child applications; controlling them; and responding to expected patterns in their output. Pexpect can be used for automating interactive applications such as ssh, ftp, passwd, telnet, etc. Pexpect is pure Python."

Sign up to request clarification or add additional context in comments.

1 Comment

pexpect will fix all the irritating buffering problems the OP has been having and would be my choice for this problem.
0

http://code.google.com/p/py-asterisk/

Introduction

The Python Asterisk package (codenamed py-Asterisk) is an attempt to produce high quality, well documented Python bindings for the Asterisk Manager API.

The eventual goal of the package is to allow rich specification of the Asterisk configuration in Python rather than in the quirky, unstructured, undocumented mess that we call the Asterisk configuration files.

Working Functionality

Python package implementing a manager client and event dispatcher. User-oriented command line interface to manager API.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.