日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

linux执行python不打印_在Python中执行shell程序而不打印到屏幕

發布時間:2025/1/21 linux 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 linux执行python不打印_在Python中执行shell程序而不打印到屏幕 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

有沒有一種方法可以讓我從Python執行一個shell程序,它將輸出打印到屏幕上,然后將它的輸出讀入變量而不在屏幕上顯示任何內容?在

這聽起來有點令人困惑,所以也許我可以用一個例子來解釋它。在

假設我有一個程序,它在執行時將某些內容打印到屏幕上bash> ./my_prog

bash> "Hello World"

當我想在Python中將輸出讀入變量時,我讀到一個好的方法是使用subprocess模塊,如下所示:

^{pr2}$

有了這個構造,我可以將程序的輸出輸出輸出到my_var(這里是"Hello World"),但是當我運行Python腳本時,它也會被打印到屏幕上。有什么辦法可以抑制這種情況嗎?我在subprocess文檔中找不到任何內容,所以可能還有另一個模塊可以用于此目的?在

編輯:

我剛發現commands.getoutput()讓我這么做。但是在subprocess中是否也有實現類似效果的方法?因為我計劃在某個時候做一個Python的版本。在

編輯2:具體例子

摘自python腳本:oechem_utils_path = "/soft/linux64/openeye/examples/oechem-utilities/"\

"openeye/toolkits/1.7.2.4/redhat-RHEL5-g++4.3-x64/examples/"\

"oechem-utilities/"

rmsd_path = oechem_utils_path + "rmsd"

for file in lMol2:

sReturn = subprocess.check_output("{rmsd_exe} {rmsd_pars}"\

" -in {sIn} -ref {sRef}".format(rmsd_exe=sRmsdExe,\

rmsd_pars=sRmsdPars, sIn=file, sRef=sReference), shell=True)

dRmsds[file] = sReturn

屏幕輸出(請注意,不是“所有內容”都打印到屏幕上,而是

輸出,如果我使用commands.getoutput一切正常:/soft/linux64/openeye/examples/oechem-utilities/openeye/toolkits/1.7.2.4/redhat-RHEL5-g++4.3-x64/examples/oechem-utilities/rmsd: mols in: 1 out: 0

/soft/linux64/openeye/examples/oechem-utilities/openeye/toolkits/1.7.2.4/redhat-RHEL5-g++4.3-x64/examples/oechem-utilities/rmsd: confs in: 1 out: 0

/soft/linux64/openeye/examples/oechem-utilities/openeye/toolkits/1.7.2.4/redhat-RHEL5-g++4.3-x64/examples/oechem-utilities/rmsd - RMSD utility [OEChem 1.7.2]

/soft/linux64/openeye/examples/oechem-utilities/openeye/toolkits/1.7.2.4/redhat-RHEL5-g++4.3-x64/examples/oechem-utilities/rmsd: mols in: 1 out: 0

/soft/linux64/openeye/examples/oechem-utilities/openeye/toolkits/1.7.2.4/redhat-RHEL5-g++4.3-x64/examples/oechem-utilities/rmsd: confs in: 1 out: 0

總結

以上是生活随笔為你收集整理的linux执行python不打印_在Python中执行shell程序而不打印到屏幕的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。