简单介绍

  subprocess模块可以创建新的进程,执行shell命令、Python脚本等

代码示例

import subprocess

# 1.执行进程,并获取返回码
return_code = subprocess.call(["ls", "-l"])
print(return_code) # 2.执行进程,并获取进程输出内容
return_cont = subprocess.check_output(["ipconfig"])
print(return_cont.decode("gbk")) # 3.传递原生shell命令字符串执行,不推荐
subprocess.call("ls -l", shell=True)
subprocess.check_output("ls -l", shell=True)

1.执行shell命令


参考资料

  http://python.usyiyi.cn/translate/python_352/library/subprocess.html

      

    

最新文章

  1. web前端基础知识 Dom
  2. svn更新操作时提示database is locked
  3. 洛谷U5653 宋荣子的小饼干
  4. ajax中文传送到模板显示为null
  5. mysql:批量更新
  6. 【工具推荐】ELMAH——可插拔错误日志工具
  7. JS - To my gril
  8. 进程kswapd0与events/0消耗大量CPU的问题
  9. handler.post 为什么要将thread对象post到handler中执行呢?
  10. LINQ to SQL语句之Join和Order By
  11. memcached在windows下的安装与命令使用方法
  12. shuffle() 函数(转)
  13. AIX-du
  14. uva 10929 - You can say 11
  15. 实现TCP断点上传,后台C#服务实现接收
  16. spark install
  17. 云计算之路-阿里云上:节点 CPU 波动引发 docker swarm 集群故障
  18. python的日志配置
  19. Spring.Net 简单实例-01(IOC)
  20. Percona XtraDB Cluster vs Galera Cluster vs MySQL Group Replication

热门文章

  1. Binlog2sql+CentOS7 离线安装
  2. 利用Python进行数据分析第六季第七集
  3. Java-接口(另类抽象)
  4. jQuery-键值对理解
  5. Java实现蓝桥杯第十一届校内模拟赛
  6. Java实现 蓝桥杯VIP 算法提高 盾神与砝码称重
  7. Java实现 LeetCode 119 杨辉三角 II
  8. Java实现 蓝桥杯VIP 算法提高 任意年月日历输出
  9. java实现还款计算
  10. Java实现有理数的循环节