summaryrefslogtreecommitdiff
path: root/basics/python/linux_shell.py
blob: cebc030e0c361f661dc37c20acd3b291be2afaae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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))