python check output find command not working
Question: I am trying to find the path to a file named 'config.txt' from a usb flash
drive plugged into a raspberry pi. The physical drive that is used may not
always be the same, so the path may not always be the same. So I use

    
    
    'find /media/pi/*/config.txt' 
    

to locate the path in the terminal and works just fine. Now I go to use
check_output and get a giant string of paths.

    
    
    from subprocess import check_output
    cmd = ['find', '/media/pi/*/config.txt']
    out = check_output(cmd,shell=True) 
    

I set the shell as True to allow wild cards, according to
<https://docs.python.org/2/library/subprocess.html>

Results for out are:

    
    
    '.\n./.Xauthority\n./.xsession-errors\n./Public\n./.dmrc\n./Downloads\n./test.sh\n./.idlerc\n./.idlerc/recent-files.lst\n./.idlerc/breakpoints.lst\n./.asoundrc\n./.bash_logout\n./.profile\n./Templates\n./Music\n./.bash_history\n./Videos\n./.local\n./.local/share\n./.local/share/gvfs-metadata\n./.local/share/gvfs-metadata/home\n./.local/share/gvfs-metadata/home-d6050e94.log\n./.local/share/applications\n./.local/share/recently-used.xbel\n./.local/share/Trash\n.....
    

And it continues to go on for awhile. I tried looking at several other similar
questions including the link below, but no luck.

[Store output of subprocess.Popen call in a
string](http://stackoverflow.com/questions/2502833/store-output-of-subprocess-
popen-call-in-a-string)


Answer: You would need to _pass a single string_ exactly as you would from your shell
if you want to use a wildcard:

    
    
    from subprocess import check_output
    cmd = 'find /media/pi/*/config.txt'
    out = check_output(cmd,shell=True)
    

You don't actually need subprocess at all,
[glob](https://docs.python.org/2/library/glob.html) will do what you want:

    
    
    from glob import glob 
    files =  glob('/media/pi/*/config.txt')
    

