subprocess popen argument with wildcard

Viewed 597

I wrote a method that is defined as below and works

def cmd_exec(cmd_tokens = []):
    p = subprocess.Popen(cmd_tokens, 
    stdout=subprocess.PIPE,stderr=subprocess.PIPE)
    out, err = p.communicate()
    return (out, err)

I have a constant as LOAD_IMAGES=['docker', 'load', '-i', 'my_img_file_101']

When I execute the above method with LOAD_IMAGES as arguments, it works fine. However, the filename number might change for me and when I try to use a wildcard, I get the error. Say when I have LOAD_IMAGES=['docker', 'load', '-i', 'my_img_file*'], I get an error from the Py/Bash as open my_img_file*: no such file or directory

How do I make the wild card work. Executing the command directly on bash works.I mean when I say this on bash, it works docker load -i my_img_file*

1 Answers
Related