似乎这应该有效,但事实并非如此。我已经玩过各种方法,比如使用范围,查看表达式是否计算为True等等。我使用local
在本地运行命令with fabric。
这就是现在的样子:
def test_health_check():
test = local('curl -I -sL -w "%{http_code} %{url_effective}\\n" --user username:username --location-mylocation "http://my.test.server:8180/something/something/something" -o /dev/null | cut -d " " -f 1')
if test == 200:
print "success"
else:
print "failure"
如果我将if测试部分设置为if test >= 200:
,那么它将评估True,但对其他任何内容评估为false。如果范围是200到302,我希望能够返回True。此外,还有更好的方法吗?
答案 0 :(得分:0)
Answered by my bro:
Assuming your curl command is set up to return the status code, I think you’d want the second arg of your
local
call to be True, so
local(‘curl stuff’, True)
as the docs say local is not capable of printing and capturing output simultaneously. The default value for the second arg is False, which is capture. You want capture.