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与操作系统交换

 

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