Skip to main content

Run a command within python

Project description

run-cmd

pytestpythonCode style: blackLicense: MITPyPI version

Run a command within python

Install it

pip install python-run-cmd
# pip install git+https://github.com/ffreemt/run-cmd
# poetry add git+https://github.com/ffreemt/run-cmd
# git clone https://github.com/ffreemt/run-cmd && cd run-cmd

Use it

from python_run_cmd import run_cmd

ret = run_cmd("ls -l")
if ret.returncode:
  print("Failed")
else:
  print("OK")

Raise an exception when errors occur. This may come handy sometimes.

from python_run_cmd import run_cmd

ret = run_cmd("lsss -l")
# 'lsss' is not recognized as an internal
# or external command, operable program or batch file.

Set raise_stderr=False to ignore errors

from python_run_cmd import run_cmd

ret = run_cmd("lsss -l", raise_stderr=False)
if ret.returncode:
  print("Failed")
else:
  print("OK")

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

python_run_cmd-0.1.0.tar.gz (3.2 kB view hashes)

Uploaded Source

Built Distribution

python_run_cmd-0.1.0-py3-none-any.whl (3.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page