Commit d71256c7 authored by Anael Beutot's avatar Anael Beutot
Browse files

Add utils function for handling subprocess.

parent 616abe5a
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
import subprocess


def and_(iter):
    """Do an and logic condition over the iterable element.

@@ -8,3 +11,17 @@ def and_(iter):
            return False

    return True


def subproc_call(args, stdin=None):
    """
    :param args: arguments for subprocess call
    :param stdin: stdin data as string
    """
    proc = subprocess.Popen(args, bufsize=4096, stdin=subprocess.PIPE,
                            stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    result, _ = proc.communicate(stdin)
    if proc.returncode != 0:
        raise subprocess.CalledProcessError(proc.returncode,
                                            'Error while executing command')
    return result