A simple interface to run a bash command from python. It wraps Popen, so it's easier to run the command. You can use Script object to write pretty bash scripts in python.
Project description
run_cmd
This code is a simple wrapper for Popen to run shell commands from python. The required version of python is 3.8 or above.
Installation:
pip
You can install it via pip:
pip install run-cmd
poetry
To install this code, you will need to first install Poetry (https://python-poetry.org/docs/#installation). Poetry is a dependency manager for Python that will allow you to easily install this code and its dependencies.
Once you have Poetry installed, you can install this code by running the following command from the root directory of this code:
poetry add run-cmd
This will install this code and all of its dependencies.
Usage:
To use this code, you can simply import the run_cmd function:
from run_cmd.run_cmd import run_cmd
print(run_cmd('ls'))
output:
LICENSE README.md log/ poetry.lock pyproject.toml run_cmd/
Then, you can call the run_cmd function with a shell command as a string:
If an error thrown it caught, and logged before, erroring out.
You can also specify whether you want the output to be returned as a list or a string:
run_cmd('ls', split=True)
This will output the result as a list, with each element being one line of output.
Script
script = Scripts()
script.cmds = """
ls
echo "an"
"""
script()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for magic_run_cmd-1.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ccb1015a726914d8ea1387bf2299c82af44514307357d8180114d2d7e276d11f |
|
MD5 | 8b7f8a156cb177e0c44279f47f630f64 |
|
BLAKE2b-256 | decc2f56b24e84064b579c7ba65ce4ea163fc776b8faa0ca83352df6817dbe57 |