diff options
| author | zhang <zch921005@126.com> | 2022-08-14 22:08:52 +0800 |
|---|---|---|
| committer | zhang <zch921005@126.com> | 2022-08-14 22:08:52 +0800 |
| commit | 756b736ca374dc6ef2adadce101f380e10f06c4e (patch) | |
| tree | a40c84446c244fdc4bf14a3420d1ca484366828d /basics/python/linux_shell.py | |
| parent | 55f511981ce22dd98dc396761a112c9d3354a4f3 (diff) | |
copy
Diffstat (limited to 'basics/python/linux_shell.py')
| -rw-r--r-- | basics/python/linux_shell.py | 25 |
1 files changed, 25 insertions, 0 deletions
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)) + |
