最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
python捕获shell/bash脚本的输出结果实例
时间:2022-06-24 15:07:46 编辑:袖梨 来源:一聚教程网
#!/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.c***yberciti.biz/faq/python-run-external-command-and-get-output/
相关文章
- 洛克王国世界圣水守护如何获得 06-16
- Canva AI企业版适合哪些场景?6个典型团队应用实例 06-16
- 我的勇者轩辕九黎系列超限武器全解析:包含属性、获取方式与实战搭配指南 06-16
- 奇门手游元宝攻略:奇门手游元宝高效使用技巧与常见避坑指南 06-16
- 金铲铲之战“怪兽入侵”返场赛季 | 经典回归 体验升级 06-16
- 失落城堡2隐藏关卡地图解锁攻略 06-16