Skip to main content

Replacement for pexpect

Project description

Import the main class:

from processcontroller import ProcessController

Create a new instance:

process_controller = ProcessController()

Run a subprogram:

process_controller.run(command, options)

The command parameter must be an array like:

['/usr/bin/python', 'file.py']

options is a bit more complexe:

Currently, it supports two keys, ‘when’ and ‘echo’.

  • when:

This key is used to listen to events occuring on the STDOUT of the subprogram The value have to be an array of events The “event” is in fact a match for some pattern:

'when': [
   ['^SomeRegex.*$', callback],
   ['^An other one.$', cb]
]

The callbacks will be called with two arguments: the ProcessController instance, and the matched string:

def callback(processcontroller, string)

You can automates user inputs in your callback when required by the subprogram using the send function of your ProcessController instance:

def cb(p, s):
   c.send('some input')
  • echo:

This key is a boolean that defaults to False. When set to True, the ProcessController will print the input sent to your subprogram where it has been asked

Don’t forget that you have to create a new instance a ProcessController everytime you want to execute a new subprogram

Please feel free to read the tests and code for a better understanding

ENJOY

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

processcontroller-0.0.1.tar.gz (2.8 kB view hashes)

Uploaded source

Built Distribution

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page