popen可以找到已有的工具

Popen can find the existing tool

我正在尝试 运行 以下内容;

def conn(ad_group):
    result = Popen(["sudo -S /opt/quest/bin/vastool", "-u host/ attrs 'AD_GROUP_NAME' | grep member"], stdout=PIPE)
    return result.stdout

在 RedHat 机器上的 python 脚本中,但我得到 FileNotFoundError: [Errno 2] No such file or directory: 'sudo -S /opt/quest/bin/vastool'

我可以在命令行 运行 命令 (sudo -S /opt/quest/bin/vastool -u host/ attrs 'AD_GROUP_NAME' | grep member) 没有问题。

我确定我在函数中搞砸了一些东西,但我需要另一双眼睛。

谢谢

您需要将整个命令设为单个字符串,并使用 shell=True 选项,因为您使用的是 shell 管道。

result = Popen("sudo -S /opt/quest/bin/vastool -u host/ attrs 'AD_GROUP_NAME' | grep member", stdout=PIPE, shell=True)