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/
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
用户体验至上的网页设计秘笈
以SQLite和PySqlite为例来学习Python DB API
![](https://img.aspxhome.com/file/2023/2/60512_0s.png)
网站制作流程及界面交互设计
![](https://img.aspxhome.com/file/UploadPic/200710/26/2007102612842449s.jpg)
ORACLE数据库应用开发常见问题及排除
分布式DBA:SQL存储过程知识总结
详细介绍查询优化技术在现实系统中的运用
Linux下MySQL整个数据库的备份与还原
asp 随机字符串函数
Python match语句的具体使用
Python jieba结巴分词原理及用法解析
![](https://img.aspxhome.com/file/2023/2/62262_0s.png)
关于php unset对json_encode的影响详解
![](https://img.aspxhome.com/file/2023/6/55356_0s.png)