1. Thomas Waldmann
  2. rsync_backup

Source

rsync_backup / exec_cmd.py

# -*- coding: ascii
"""
execute (shell or other) commands

author: Thomas Waldmann
license: BSD
"""

import subprocess


def exec_cmd(cmd, input=None):
    p = subprocess.Popen(cmd, shell=True,
                        close_fds=not subprocess.mswindows,
                        bufsize=1024,
                        stdin=subprocess.PIPE,
                        stdout=subprocess.PIPE,
                        stderr=subprocess.PIPE)
    data, errors = p.communicate(input)
    return data, errors, p.returncode