[root@bogon IP]# vim bash3.py
!/usr/bin/env python
import subprocess
p = subprocess.Popen('ls', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
for line in p.stdout.readlines():
print line,
retval = p.wait()
測試:
[root@bogon IP]# chmod u+x bash3.py
[root@bogon IP]# python bash3.py
bash2.py
bash3.py
bash.py
ip.py
[root@bogon IP]#