python 捕获 shell/bash 脚本的输出结果
2014-06-19 10:44
686 查看
#!/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/
## 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 捕获 shell/bash 脚本的输出结果实例
- python 捕获shell脚本的输出结果实例
- python 捕获 shell 脚本的输出结果
- Java代码中调用shell脚本和python脚本并获得输出结果(分为小数据量和大数据量)
- 从Linux程序中执行shell(程序、脚本)并获得输出结果(转)
- 从Linux程序中执行shell(程序、脚本)并获得输出结果
- python输出shell命令执行结果
- 从Linux程序中执行shell(程序、脚本)并获得输出结果(转)
- Bash Shell脚本:输入时间,输出距离你的生日天数
- shell 脚本 变量 获取程序输出结果异常分析
- shell将脚本输出结果记录到日志文件的实现
- 从Linux程序中执行shell(程序、脚本)并获得输出结果(转)
- 从Linux程序中执行shell(程序、脚本)并获得输出结果(转)
- 从Linux程序中执行shell(程序、脚本)并获得输出结果
- 从Linux程序中执行shell(程序、脚本)并获得输出结果
- LINUX下用SHELL脚本执行带输入输出参数的ORACLE存储过程并得到结果
- shell将脚本输出结果记录到日志文件
- 从Linux程序中执行shell(程序、脚本)并获得输出结果
- shell脚本wc命令详解!!需求输出结果