python subprocess 模块
生活随笔
收集整理的這篇文章主要介紹了
python subprocess 模块
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
subprocess 模塊中有一個(gè)功能Popen , 可以在代碼中調(diào)用系統(tǒng)的命令
其功能比os.system 更加強(qiáng)大
代碼示例:
command = 'python -u %s/generalMaker.py %s %s' % (module_dir, ' '.join(sys.argv[1:]), flagsToAppend) args = shlex.split(command) generalMaker = Popen(args) generalMaker.wait()上述代碼中,首先用shlex.split 函數(shù)分割命令行參數(shù),然后將參數(shù)傳遞給Popen 函數(shù),執(zhí)行對(duì)應(yīng)的系統(tǒng)命令,wait() 函數(shù)表示等待系統(tǒng)命令執(zhí)行結(jié)束
?
總結(jié)
以上是生活随笔為你收集整理的python subprocess 模块的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: HDU2521 反素数【因子数量+打表】
- 下一篇: Python探索记(01)——Hello