mirror of
https://github.com/Foltik/dotfiles
synced 2024-11-24 04:22:50 -05:00
17 lines
516 B
Python
17 lines
516 B
Python
import subprocess
|
|
|
|
def exec(cmd, sudo = False):
|
|
#print(cmd)
|
|
return subprocess.Popen(['sudo'] + cmd if sudo else cmd,
|
|
stderr = subprocess.PIPE,
|
|
stdout = subprocess.PIPE,
|
|
stdin = subprocess.PIPE)
|
|
|
|
def communicate(proc, cmd, success_retvals = [0]):
|
|
data = proc.communicate()
|
|
|
|
if proc.returncode not in success_retvals:
|
|
raise Exception('Command failed: "' + ' '.join(cmd) + '"' + data[1].decode())
|
|
|
|
return data[0].decode()
|