import subprocess
# res = s.Popen(r'dir C:\Users',shell=True) # 执行系统命令
# print(res) 但是打印输出不是很好看
# 管道,标准输出
# res = subprocess.Popen(r'dir C:\Users', shell=True, stdout=subprocess.PIPE)
# print(res.stdout.read().decode("gbk"))
# 管道,错误输出
# res = subprocess.Popen(r'ls C:\Users', shell=True, stdout=subprocess.PIPE)
# print(res.stdout.read().decode('gbk'))
# 管道,标准输入
res1 = subprocess.Popen(r'dir C:\Users\liqi\PycharmProjects\pythonProject', shell=True, stdout=subprocess.PIPE)
res2 = subprocess.Popen(r'mkdir newdir_2', shell=True, stdin=res1.stdout, stdout=subprocess.PIPE)
print(res1.stdout.read().decode('gbk'))
print(res2.stdout.read().decode('gbk'))
参考资料