Search code examples
pythonsubprocesspopen

Popen can find the existing tool


I'm trying to run the following;

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

on a RedHat machine in a python script but I'm getting FileNotFoundError: [Errno 2] No such file or directory: 'sudo -S /opt/quest/bin/vastool'

I can run the command(sudo -S /opt/quest/bin/vastool -u host/ attrs 'AD_GROUP_NAME' | grep member) at the command line without a problem.

I'm sure I've messed up something in the function but I need an other set of eyes.

Thank you


Solution

  • You need to make the entire command a single string, and use the shell=True option because you're using a shell pipeline.

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