警告:sudo()在执行时遇到错误(返回码1):Fabric

问题描述:

我是新来面料。我试图检查setkey是否安装在远程机器上。为此,我只是想检查它的版本号,如果它返回一个错误,那么它将安装所需的软件包。以下是代码警告:sudo()在执行时遇到错误(返回码1):Fabric

with settings(hide('stdout'), warn_only=True): 
    out = sudo('setkey -V', shell=False); 
    if out.failed: 
     print(red("* Setkey not installed. Installing")) 
     sudo(setkey_install) 

但是我得到一个警告

警告:sudo的()遇到一个错误(返回码1)在执行 '的setkey -V'

这可能是什么原因?是否有任何其他方式来检查包是否安装?

我会使用* nix的命令which返回的位置setkey(或什么,如果不存在的话),像这样的东西:命令

with settings(hide('stdout'), warn_only=True): 
    if not run('which setkey'): 
     print(red("* Setkey not installed. Installing...")) 
     sudo(setkey_install) 

由于run返回输出它给了你应该能够像这样使用not运营商。