警告:sudo() 在执行时遇到错误(返回代码 1):Fabric
我是布料新手。我正在尝试检查远程计算机上是否安装了 setkey。为此,我只是想检查它的版本号,如果它返回错误,那么它将安装所需的包。以下是代码
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)
但是我收到警告
警告:执行“setkey -V”时 sudo() 遇到错误(返回代码 1)
这可能是什么原因?还有其他方法可以检查软件包是否已安装吗?
I'm new to fabric. I'm trying to check if setkey is installed in the remote machine. For that I'm just trying to check its version number and if it returns an error then it will install the required package. The following is the code
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)
However I'm getting a warning
Warning: sudo() encountered an error (return code 1) while executing 'setkey -V'
What could be the reason for this? Is there any other way to check if a package is installed?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我将使用 *nix 命令
which
返回setkey
的位置(如果不存在则不返回任何内容),如下所示:Since
run
返回给定命令的输出,您应该能够像这样使用not
运算符。I would use the *nix command
which
to return the location of thesetkey
(or nothing if it doesn't exist), with something like this:Since
run
returns the output of the command it's given you should be able to use thenot
operator on it like this.