zoukankan      html  css  js  c++  java
  • subprocess 模块

    import subprocess
    # 就用来执行系统命令
    import os
    
    cmd = r'dir D:上海python全栈4期day23 | findstr "py"'
    # res = subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
    # # 从管道中读取数据   管道就是 两个进程通讯的媒介
    # # print(type(res.stdout.read().decode("GBK")))
    # print(res.stdout.read().decode("GBK"))
    # print(res.stderr.read().decode("GBK"))
    
    dir = r'dir D:上海python全栈4期day23'
    find = 'findstr "py"'
    """
    stdout 输出管道
    stdin 输入管道
    stderr 错误管道
    """
    res1 = subprocess.Popen(dir,shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
    
    res2 = subprocess.Popen(find,shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE,stdin=res1.stdout)
    # 从管道中读取数据   管道就是 两个进程通讯的媒介
    # print(type(res.stdout.read().decode("GBK")))
    # print(res1.stdout.read().decode("GBK"))
    print(res2.stderr.read().decode("GBK"),"33333")
    
    
    
    # 简单总结  subprocess 主要用于执行系统指令 (启动子进程) 与os.system的不同在于
    # subprocess 可以与这个子进程进行数据交换
  • 相关阅读:
    MySQL 三节点企业版
    Raft 一致性算法论文译文 JAVA
    MySQL EXPLAIN 命令详解学习
    MySQL 5.7.17 Group Replication 初始
    JAVA 线程池以及其他
    什么是IIS并发连接数
    CUDA
    各种学习手册在线
    弱电系统标准CAD图例识图讲解
    ACM---算法
  • 原文地址:https://www.cnblogs.com/TF511/p/9821421.html
Copyright © 2011-2022 走看看