import subprocess # 子进程的意思
obj = subprocess.Popen(r'dir F:\学习课件\python\项目', shell=True, # 如果是mac,'ls /'
stdout=subprocess.PIPE, # 把正确结果放到管道里
stderr=subprocess.PIPE, # 把错误结果放到管道里
)
# print(obj)
res = obj.stdout.read()
print(res.decode('GBK')) # 使用计算机系统的解码格式
'''
D:\python3.8.5\python.exe F:/学习课件/python/练习/run.py
驱动器 F 中的卷是 工作
卷的序列号是 16DA-0A10
F:\学习课件\python\项目 的目录
2020/12/17 14:47 <DIR> .
2020/12/17 14:47 <DIR> ..
2020/12/16 21:11 <DIR> ATM
2020/12/17 10:48 29,755 ATM.zip
1 个文件 29,755 字节
3 个目录 177,912,426,496 可用字节
Process finished with exit code 0
'''
# res1 = obj.stderr.read()
# print(res1.decode('GBK')) # 如果有文件为空,没有文件就显示,找不到文件