python 捕获 shell/bash 脚本的输出结果实例,pythonbash
python 捕获 shell/bash 脚本的输出结果实例,pythonbash
#!/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/
以上就是小编为大家带来的python 捕获 shell/bash 脚本的输出结果实例全部内容了,希望大家多多支持帮客之家~
相关内容
- 详解使用python crontab设置linux定时任务,pythoncrontab
- 请不要重复犯我在学习Python和Linux系统上的错误,pyth
- windows及linux环境下永久修改pip镜像源的方法,linuxpip
- Python彩色化Linux的命令行终端界面的代码实例分享,p
- Linux上安装Python的PIL和Pillow库处理图片的实例教程,
- Python提取Linux内核源代码的目录结构实现方法,pythonl
- Google开源的Python格式化工具YAPF的安装和使用教程,py
- Python获取linux主机ip的简单实现方法,pythonlinux主机ip
- Python实现Linux命令xxd -i功能,pythonxxd
- Linux系统上Nginx+Python的web.py与Django框架环境,
评论关闭