2018-12-08 23:18:25 -05:00
|
|
|
import subprocess
|
|
|
|
|
2018-12-09 00:45:33 -05:00
|
|
|
def exec(cmd, sudo = False):
|
2018-12-08 23:18:25 -05:00
|
|
|
#print(cmd)
|
2018-12-09 00:45:33 -05:00
|
|
|
return subprocess.Popen(['sudo'] + cmd if sudo else cmd,
|
2018-12-08 23:18:25 -05:00
|
|
|
stderr = subprocess.PIPE,
|
|
|
|
stdout = subprocess.PIPE,
|
|
|
|
stdin = subprocess.PIPE)
|
|
|
|
|
2018-12-09 00:45:33 -05:00
|
|
|
def communicate(proc, cmd, success_retvals = [0]):
|
2018-12-08 23:18:25 -05:00
|
|
|
data = proc.communicate()
|
|
|
|
|
2018-12-09 00:45:33 -05:00
|
|
|
if proc.returncode not in success_retvals:
|
|
|
|
raise Exception('Command failed: "' + ' '.join(cmd) + '"' + data[1].decode())
|
2018-12-08 23:18:25 -05:00
|
|
|
|
|
|
|
return data[0].decode()
|