lazy-command

Rust-like command wrapper over subprocess


Keywords
subprocess
License
MIT
Install
pip install lazy-command==0.1

Documentation

lazy-command.py

The Rust-like wrapper over subprocess.PIPE

The idea behind this wrapper is to customize command by means of method chaining.

Examples

Collect all output of command

from lazy_command import Command

output = Command('make').arg(target).arg('-n').all_pipe().output()

print("return code={} | stdout={} | stderr={}".format(output.status,
                                                      output.stdout,
                                                      output.stderr))

Just check status code

from lazy_command import Command

return_code = (Command('grep').arg('something')
                              .arg('-r')
                              .arg('.')
                              .stdout_null()
                              .status())

print("grep returns {}".format(return_code))

Set command in one go

Under hood Command uses shlex.split so you can set the whole command in one go.

from lazy_command import Command

return_code = Command('grep something -r .').stdout_null().status()

print("grep returns {}".format(return_code))