import subprocess
file_output = open("debug.txt","w") subprocess.Popen("ipconfig",stdout= file_output).wait() ######输出重定向,不卡住界面也不会因输出而在生成exe时有问题,如果不需要等待子进程结束,去掉.wait即可
file_output.close()
cmd_sys = subprocess.Popen('ipconfig',stdout=subprocess.PIPE)######将命令执行结果获取到 赋值给cmd_res cmd_res = cmd_sys.stdout.read()