run os command

This commit is contained in:
Daniel Tsvetkov 2020-05-11 20:29:25 +02:00
parent d8f255e8ea
commit 384d7c9a11
2 changed files with 19 additions and 0 deletions

0
oshipka/util/__init__.py Normal file
View File

19
oshipka/util/os.py Normal file
View File

@ -0,0 +1,19 @@
import subprocess
def run_cmd(command):
process = subprocess.Popen(command.split(),
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
universal_newlines=True,
)
return '\n'.join([str(line) for line in iter(process.stdout.readline, '')])
def print_cmd(command):
for line in run_cmd(command):
print(line, end='')
if __name__ == "__main__":
print_cmd("env")