1
0
mirror of https://github.com/altlinux/gpupdate.git synced 2025-03-21 18:50:38 +03:00

runcmd(): Run program and check return code

This commit is contained in:
Игорь Чудов 2020-08-17 18:40:45 +04:00
parent 165f0defa7
commit 3f1edd2791
Signed by untrusted user: nir
GPG Key ID: 0F3883600CAE7AAC

View File

@ -20,6 +20,7 @@
import socket
import os
import pwd
import subprocess
from pathlib import Path
@ -83,3 +84,16 @@ def mk_homedir_path(username, homedir_path):
os.chown(homedir, uid=uid, gid=gid)
longer_path = os.path.join(longer_path, elem)
def runcmd(command_name):
'''
Run application.
'''
try:
with subprocess.Popen(command_name, stdout=subprocess.PIPE) as proc:
value = proc.stdout.read().decode('utf-8')
proc.wait()
rc = proc.returncode
return (rc, value)
except Exception as exc:
print(str(exc))