赞
踩
Python内执行DOS命令其中的两种实现方式
第一种使用os.system()直接返回结果
第二种使用os.popen(),将返回值存为文件形式,再读取文件内容展现返回结果
代码:
import os
// 第一种
instructions1 = input("输入命令1:")
os.system(instructions1)
//第二种
instructions2 = input("输入命令2:")
with os.popen(instructions2,"r")as f:
text = f.read()
print(text)
效果
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。