Skip to main content

A Python shell command helper using the subprocess Popen.

Project description

About

easybash Basher helps you to easily and safely run BASH commands in a Python program using subprocess Popen.

It's basically a subprocess Popen wrapper.

The idea is to provide an easy way to execute shell commands without compromising safety. Even though it's possible to pass shell=True to Popen in order to execute complex commands, it's not recommended and it's mostly not needed with this package.

Used libraries

shlex
subprocess
time

This package requires no Python third party libraries.

Installation

You can install it directly from PyPi using pip:

pip install easybash

You can also install it directly from this repository:

pip install git+https://github.com/andreluisos/easybash.git

Usage

Importing

Basher is an object of easybash. So you can import it with the following code:

from easybash import Basher

Running a command and waiting for the execution to end

from easybash import Basher

Basher('sleep 3')

You can add a message

from easybash import Basher

Basher('sleep 3', msg='Sleeping for 3 seconds')

msg example

You can debug the execution

from easybash import Basher

Basher('sleep 3', msg='Sleeping for 3 seconds', debug=True)

debug example

You can print the stdout/stderr of the command

from easybash import Basher

print(Basher('ls', msg='Listing files in this dir').stdout)

stdout1 example

You can do whatever you want with the output

from easybash import Basher

[print(line) for line in Basher('ls').stdout.split()]

stdout2 example

You don't have to wait for command execution to keep running your code

from easybash import Basher

cmd = Basher('sleep 20', wait=False)
print(cmd.pid)

wait example

Basher will automatically reconize pipes, so you can easily run commands

Redirections are being implemented.

from easybash import Basher

print(Basher('ls | wc -l | wc -l').stdout)

pipe example

You can change the current working directory

from easybash import Basher

print(Basher('ls', cwd='/home/andreluisos/test').stdout)

cwd example

You can pass shell=True, but it's not recomended!

The idea of the module is to provide an easy way to execute shell commands without compromising safety. Redirections will be implemented soon.

from easybash import Basher

Basher('ls', shell=True)

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

easybash-1.0.0.tar.gz (16.3 kB view hashes)

Uploaded Source

Built Distribution

easybash-1.0.0-py3-none-any.whl (16.6 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