python 捕獲 shell/bash 腳本的輸出結(jié)果實例
#!/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/
以上就是小編為大家?guī)淼膒ython 捕獲 shell/bash 腳本的輸出結(jié)果實例全部內(nèi)容了,希望大家多多支持腳本之家~
相關文章
python高效過濾出文件夾下指定文件名結(jié)尾的文件實例
今天小編就為大家分享一篇python高效過濾出文件夾下指定文件名結(jié)尾的文件實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-10-10
Python使用collections模塊實現(xiàn)擴展數(shù)據(jù)類
Python?標準庫提供了一個?collections?模塊,里面提供了很多的數(shù)據(jù)類,在工作中使用這些類能夠簡化我們的開發(fā),本文就來看看collections是如何實現(xiàn)擴展數(shù)據(jù)類的吧2023-06-06
python?AutoViz庫一行代碼實現(xiàn)可視化數(shù)據(jù)集
這篇文章主要介紹了python?AutoViz庫一行代碼實現(xiàn)可視化數(shù)據(jù)集實例探索,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2024-01-01

