From 756b736ca374dc6ef2adadce101f380e10f06c4e Mon Sep 17 00:00:00 2001 From: zhang Date: Sun, 14 Aug 2022 22:08:52 +0800 Subject: copy --- basics/python/linux_shell.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 basics/python/linux_shell.py (limited to 'basics/python') diff --git a/basics/python/linux_shell.py b/basics/python/linux_shell.py new file mode 100644 index 0000000..cebc030 --- /dev/null +++ b/basics/python/linux_shell.py @@ -0,0 +1,25 @@ + +import subprocess +from subprocess import Popen, PIPE + +# cmd = 'sleep 2' + +cmd = 'df -h' + +p = Popen(cmd.split(' '), + # shell=True, + # stdout=subprocess.DEVNULL, + stdout=PIPE, + universal_newlines=True + ) + + +p.wait() +out = p.communicate() +print('out: {}'.format(out)) + +if p.returncode == 0: + print('{} success'.format(cmd)) +else: + print('{} failed'.format(cmd)) + -- cgit v1.2.3