Shell

This is one of the innermost classes. The parameters are passed to the constructor and then you can call run() or use an Executor instance to run in parallel.

>>> from expyrimenter import Shell
>>> Shell('echo Hello', stdout=True).run()
'Hello'
>>> # You can use try/except
>>> from subprocess import CalledProcessError
>>> try:
>>>     Shell('wrongcommand').run()
>>> except CalledProcessError as e:
>>>     print("Failed: %s" % e.output)
Failed: /bin/sh: 1: wrongcommand: not found
class expyrimenter.Shell(cmd, title=None, stdout=False, stderr=True)[source]

Bases: expyrimenter.runnable.Runnable

Parameters:
  • cmd (str) – Command with arguments to be run.
  • title (str) – A title to be displayed in log outputs. If None, cmd will be shown.
  • stdout (bool) – Whether or not to display standard output. Default is False.
  • stderr (bool) – Whether or not to display standard error. Default is True.
command

The command to be run in shell.

Return type:str
has_failed()[source]

Runs the command and returns whether the return code differs from 0.

Returns:whether the command has failed.
Return type:bool
run()[source]

If the command exits 0, returns 0 or the stdout/stderr output. Otherwise, raises CalledProcessError.

Returns:shell return code (0) or output.
Return type:int or str
Raises CalledProcessError:
 if return code is not 0.
title

If the title is not set, returns command().

Return type:str
was_successful()[source]

Runs the command and returns whether the return code is 0.

Returns:whether the command was successful.
Return type:bool