• 网站首页
  • 网络编程
    • PHP笔记
    • JavaScript
    • HTML
    • AJAX
    • jQuery
    • Python
  • 数据库
    • MySQL
    • SQL Server
当前位置:首页 > 网络编程 > Python

python 捕获 shell/bash 脚本的输出结果的简单示例

人气:30 时间:2018-10-29

这篇文章主要为大家详细介绍了python 捕获 shell/bash 脚本的输出结果的简单示例,具有一定的参考价值,可以用来参考一下。

感兴趣python 捕获 shell/bash 脚本的输出结果的简单示例的小伙伴,下面一起跟随512笔记的小编罗X来看看吧。<br>
#!/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
 

注:关于python 捕获 shell/bash 脚本的输出结果的简单示例的内容就先介绍到这里,更多相关文章的可以留意512笔记的其他信息。

关键词:shell

您可能感兴趣的文章

  • python 捕获 shell 脚本的输出结果的简单示例
  • php+shell 检测文件类型实现方法
转载请注明出处:512笔记
本文永久地址:http://www.512pic.com/181/2772-0.html
上一篇:python 捕获 shell 脚本的输出结果的简单示例
下一篇:Python 读写文件实现方法
最新文章
  • python爬取网页数据
  • python爬虫最简单代码
  • python简单爬虫代码
  • 有趣的python爬虫项目
  • python微博爬虫实例
  • python小实例一:简单爬虫
  • python爬虫简单实例
  • python爬虫获取百度搜索结果的简单示例
  • python解决网站爬虫限制的简单示例
  • python带异常处理的简单示例
本月热门
  • python爬虫最简单代码
  • python爬虫代码示例
  • 有趣的python爬虫项目
  • python带异常处理的简单示例
  • python爬虫获取百度搜索结果的简单示例
  • python小实例一:简单爬虫
  • python爬虫简单实例
  • python微博爬虫实例
  • python爬取网页数据
  • python解决网站爬虫限制的简单示例
  • 热门文章
    • Python 不得不知的开源项目解析
    • Python遍历文件脚本的简单示例
    • Python解决json.dumps错误::‘utf8’ codec can‘t decode byte
    • Python函数功能实例
    • python货币格式化功能实例
    • python 局部变量与全局变量功能实例
    • Python 10款最好的IDE示例
    • python进制转换的简单示例(二进制、十进制、十六进制)
    • python备份VPS的网站文件及数据库的简单示例
    • Python文本文件输入输出的简单示例
    • python 文件操作的功能实例
    • Python使用sys.argv[] 示例
    • python基础知识2:列表与元组
    • python 删除文件、删除目录的实现示例
    • Python制作简单刷微博入门实例
    • Python struct.pack()和struct.unpack()用法功能实例
    • 初学者学习python2还是学习python3解析
    • Python代码更加pythonic的简单示例
    • Python Hello World!的简单示例
    • python面试题解析

All rights reserved. 512笔记. 网站地图 友情连接 招募投稿 广告服务