我想從下面的代碼中獲取數字值。當我「打印」出價值時,我會得到一個數字「1」。然而,當它進入「if」語句時,我總是將「closed」作爲「STORE」中的存儲變量。代碼的第三行用於刪除回車。使用子進程隱藏字符.Popen
CLOSED = subprocess.Popen(
[
"ssh",
"hostname",
"/usr/blaine/store_status | grep 00 | awk \{\'print $5\'\}"
],
stdout=subprocess.PIPE
)
CLOSED_OUTPUT = CLOSED.stdout.read()
CLOSED_OUTPUT = CLOSED_OUTPUT.replace('\n','')
(有一個很難得到的if語句正確顯示,我確實有正確的凹痕,如果我給你的變量它的工作)
if CLOSED_OUTPUT == 1:
STORE = "open"
else:
STORE = "closed"
print ("The store is %s." % (STORE))
謝謝科林,這解決了我的問題。 –