python 捕获 shell/bash 脚本的输出结果
#!/usr/bin/python
## get subprocess module
import subprocess
## call date command ##
p = subprocess.Popen("date", stdout=subprocess.PIPE, shell=True)
## Talk with date command i.e. read data from stdout and stderr. Store this info in tuple
## Interact with process: Send data to stdin. Read data from stdout and stderr,
## until end-of-file is reached.Wait for process to terminate. The optional input
## argument should be a string to be sent to the child process, or None,
## if no data should be sent to the child. ##
(output, err) = p.communicate()
## Wait for date to terminate. Get return returncode ##
p_status = p.wait()
print "Command output : ", output
print "Command exit status/return code : ", p_status
## from: http://www.cyberciti.biz/faq/python-run-external-command-and-get-output/
最新文章
- 1Z0-053 争议题目解析501
- 大文件下载控件(down2)-示例更新-Xproer.HttpDownloader
- 转载:Spring AOP (上)
- poj2407 Relatives 欧拉函数基本应用
- ext 参考资料
- Android启动时间测试方法
- js常用效果
- 根据select不同的选项实现相应input框添加项的显示
- jQuery中$(function(){})与(function($){})(jQuery)、$(document).ready(function(){})等的区别详细讲解 ----转载
- Eureka的工作原理以及它与ZooKeeper的区别
- 经典51道SQL查询练习题
- gentoo Cataclysm - Dark Days Ahead
- java学习笔记(九):Java 流(Stream)、文件(File)和IO
- 在Idea创建Spring Boot + MyBatis的web项目
- 使用perfect进行服务端开发
- Asp.net中汉字转换成为拼音
- 用到的设计模式总结--单例模式+工厂方法模式+Builder模式
- 微服务之springCloud和docker-provide(二)
- P2167 [SDOI2009]Bill的挑战
- linux /dev 常见特殊设备介绍与应用[loop,null,zero,full,random]