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)容了,希望大家多多支持腳本之家~
相關(guān)文章
python自定義函數(shù)def的應(yīng)用詳解
這篇文章主要介紹了python自定義函數(shù)def的應(yīng)用詳解,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-06-06使用Keras構(gòu)造簡單的CNN網(wǎng)絡(luò)實例
這篇文章主要介紹了使用Keras構(gòu)造簡單的CNN網(wǎng)絡(luò)實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-06-06淺談Python使用pickle模塊序列化數(shù)據(jù)優(yōu)化代碼的方法
這篇文章主要介紹了淺談Python使用pickle模塊序列化數(shù)據(jù)優(yōu)化代碼的方法,pickle模塊可以對多種Python對象進行序列化和反序列化,序列化稱為pickling,反序列化稱為unpickling,需要的朋友可以參考下2023-07-07如何計算 tensorflow 和 pytorch 模型的浮點運算數(shù)
FLOPs 是 floating point operations 的縮寫,指浮點運算數(shù),可以用來衡量模型/算法的計算復(fù)雜度。本文主要討論如何在 tensorflow 1.x, tensorflow 2.x 以及 pytorch 中利用相關(guān)工具計算對應(yīng)模型的 FLOPs,需要的朋友可以參考下2022-11-11