1import subprocess as sp
2output = sp.getoutput('whoami --version')
3print (output)
1#!/usr/bin/python
2import subprocess, sys
3## command to run - tcp only ##
4cmd = "/usr/sbin/netstat -p tcp -f inet"
5## run it ##
6p = subprocess.Popen(cmd, shell=True, stderr=subprocess.PIPE)
7## But do not wait till netstat finish, start displaying output immediately ##
8while True:
9 out = p.stderr.read(1)
10 if out == '' and p.poll() != None:
11 break
12 if out != '':
13 sys.stdout.write(out)
14 sys.stdout.flush()