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