我想从下面的代码中获取数字值。当我“打印”出价值时,我会得到一个数字“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))
谢谢科林,这解决了我的问题。 –