From 384d7c9a119e2d65c3bd9f8453a8e103aae7b5c7 Mon Sep 17 00:00:00 2001 From: Daniel Tsvetkov Date: Mon, 11 May 2020 20:29:25 +0200 Subject: [PATCH] run os command --- oshipka/util/__init__.py | 0 oshipka/util/os.py | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 oshipka/util/__init__.py create mode 100644 oshipka/util/os.py diff --git a/oshipka/util/__init__.py b/oshipka/util/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/oshipka/util/os.py b/oshipka/util/os.py new file mode 100644 index 0000000..637e8b3 --- /dev/null +++ b/oshipka/util/os.py @@ -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") \ No newline at end of file