python 捕获 shell/bash 脚本的输出结果实例

作者:jingxian 时间:2023-10-04 15:27:41 

#!/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/

标签:linux,shell脚本,bash
0
投稿

猜你喜欢

  • 用户体验至上的网页设计秘笈

    2007-09-07 10:16:00
  • 以SQLite和PySqlite为例来学习Python DB API

    2023-07-13 02:19:14
  • 网站制作流程及界面交互设计

    2007-10-26 12:00:00
  • ORACLE数据库应用开发常见问题及排除

    2010-07-26 13:17:00
  • 分布式DBA:SQL存储过程知识总结

    2009-02-24 17:17:00
  • 详细介绍查询优化技术在现实系统中的运用

    2009-01-04 13:34:00
  • Linux下MySQL整个数据库的备份与还原

    2008-12-29 13:20:00
  • asp 随机字符串函数

    2011-04-04 11:01:00
  • Python match语句的具体使用

    2023-07-24 03:10:08
  • Python jieba结巴分词原理及用法解析

    2023-08-29 17:43:36
  • 关于php unset对json_encode的影响详解

    2023-07-06 08:33:52
  • JScript 的内存回收

    2007-10-16 20:02:00
  • Mysql Innodb 引擎优化

    2010-10-25 20:01:00
  • CSS布局之浮动(三)自适应

    2008-08-19 12:49:00
  • js读取图片的宽和高

    2007-08-04 10:14:00
  • 带你轻松接触MaxDB和MySQL之间的协同性

    2008-12-03 17:10:00
  • Python NumPy实用函数笔记之allclose

    2023-08-24 18:09:12
  • IE8 的 JSON 解析 Bug

    2009-05-22 12:36:00
  • chr()函数参照表 chr13 chr10 chr34

    2009-09-03 13:22:00
  • MySQL数据库中的重要数据应当如何保护

    2008-12-17 15:56:00
  • asp之家 网络编程 m.aspxhome.com