Python與操作系統CMD命令交互

os.popen()

import os
# 執行錯誤命令就返回亂碼
r = os.popen('ipconfig')
# read讀取執行結果
print(r.read())

subprocess.Popen()

import subprocess
r = subprocess.Popen('dir', shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

Python與操作系統交換

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章