Python cmd 获取shell 输出 简单易懂,推荐使用 import os cmd = 'dir' res = os.popen(cmd) output_str = res.read() # 获得输出字符串 print(output_str)