python 捕獲 shell/bash 腳本的輸出結果實例
#!/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 腳本的輸出結果實例全部內(nèi)容了,希望大家多多支持腳本之家~
相關文章
淺談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ù),可以用來衡量模型/算法的計算復雜度。本文主要討論如何在 tensorflow 1.x, tensorflow 2.x 以及 pytorch 中利用相關工具計算對應模型的 FLOPs,需要的朋友可以參考下2022-11-11