更新:不鼓励使用os.system,尽管它在python 3中仍然可用。
使用
os.system
:
os.system(my_cmd)
如果您真的想使用subprocess,下面是解决方案(主要是从subprocess的文档中提取的):
p = subprocess.Popen(my_cmd, shell=True)
os.waitpid(p.pid, 0)
哦,你可以完全避免系统调用:
import shutil
with open('myfile', 'w') as outfile:
for infile in ('file1', 'file2', 'file3'):
shutil.copyfileobj(open(infile), outfile)