Skip to main content

Connects subprocesses as pipe easily

Project description

pipe-subprocess

' Connects input/ouput streams between multiple subprocesses easily just like shell pipe. ' Provides almost the same interface as python subprocess module with some exceptions.

Install

pip3 install pipe-subprocess

Quick how to

Just pass commands to run function.

>>> import pipesubprocess as pipesub
>>> result = pipesub.run(["ls /usr/bin/", "grep py", "head -2"], stdout=pipesub.PIPE)
>>> print(result.stdout)
pbcopy
pydoc

# Commands can be written just as *args.

```python
>>> result = pipesub.run("ls /usr/bin/", "grep py", "head -2")
>>> print(result.stdout)
pbcopy
pydoc

run() quick glance.

Use run() function to run multiple piped subprocesses. In more complecated case, use pipesubporcess.Popen.

def run(*cmdlist, shlex=True, stdin=None, input=None, stdout=None, stderr=None, capture_output=True, shell=False, cwd=None, timeout=None, check=False, encoding=None, errors=None, text=True, env=None, universal_newlines=None)
  • It runs multiple process specified in cmdlist and connects stdout and stdin in the order of cmdlist.
  • It returns CompletedProcess()
  • input is written to stdin of the first command.
  • When timeout ([second] in float) is specified, it raises pipesubprocess.TimeoutExpired() when commands takes longer than that timeout.
  • If check=True, it raises pipesubprocess.CalledProcessError() when there is a command with exit code not zero. ' See [README_details.md] for other options.

class pipesubprocess.PipeSubprocessError

All exceptions of pipesubprocess module inherits this exception. So all exceptions of thie module can be catched by this exception.

class pipesubprocess.PopenArgs

  • It represents the arguments of one process passed to *subproces.Popen().
  • name
    • name of the argument. The first args by default.
  • See [README_details.md] for other attributes.

class pipesubprocess.CompletedProcess

  • The return value from run(), representing the finish status of processes.
  • popen_args_list
    • List of PopenArgs instance.
  • returncodes
    • List of return codes. None if all commands have not finished yet.
  • stdout
    • stdout of the last command. , stderr
    • gathred stderr of all the commands.
  • check_returncodes()
    • raises pipesubprocess.CalledProcessError() when returncodes have any non-zero status.

class pipesubprocess.TimeoutExpired

  • popen_args
    • List of PopenArgs instance.
  • timeout
    • timeout value specified.
  • stdout
    • stdout of the last command.
  • stderr
    • gathred stderr of all the commands.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

pipe_subprocess-0.3.7-py3-none-any.whl (12.4 kB view details)

Uploaded Python 3

File details

Details for the file pipe_subprocess-0.3.7-py3-none-any.whl.

File metadata

  • Download URL: pipe_subprocess-0.3.7-py3-none-any.whl
  • Upload date:
  • Size: 12.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.40.1 CPython/3.7.4

File hashes

Hashes for pipe_subprocess-0.3.7-py3-none-any.whl
Algorithm Hash digest
SHA256 3a626db1459578b8e31f3c3a46c117e14199a11ce7ac49461efa4ca7aaeaecb0
MD5 1196b1ae124ce5e4fbbaed90ab51bdea
BLAKE2b-256 b077682a0160106f00c5de35bb0758ffb249f92ebbb1d7f2231f3c3be010f4c6

See more details on using hashes here.

Supported by

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