python subprocess

1. os.popen() and subprocess.Popen()

 

o=os.popen('ls *.py').read()

print(o)

 

等于

 

s=subprocess.Popen('ls *.py',shell=True,stdout=subprocess.PIPE).communicate()[0]

print(s)

 

等于

 

>>> s=check_output('dir/b|dir/b *.py',shell=True,universal_newlines=True)

>>> print(s)

 

2. os.system() and subprocess.call()

 

os.system('ls -al')

 

等于

 

subprocess.call('ls -al',shell=True)

 

等于

 

subprocess.check_call('ls -al',shell=True)

你可能感兴趣的:(process)