import subprocess cmd = input(">>>: ") res = subprocess.Popen( cmd, # 字符串指令,如dir 或 ipconfig等等 shell=True, # 使用shell,就相當於使用cmd窗口 stderr=subprocess.PIPE, # 標准錯誤輸出,PIPE為管道 stdout=subprocess.PIPE, # 標准輸出 ) print(res.stdout.read().decode("gbk")) # window讀出的就是GBK編碼的 print(res.stderr.read().decode("gbk")) # stdout.read()讀出來的數據是bytes類型