diff options
Diffstat (limited to 'basics/python')
| -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)) + |
