The Python Oracle

python check output find command not working

--------------------------------------------------
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Industries in Orbit Looping

--

Chapters
00:00 Python Check Output Find Command Not Working
01:06 Answer 1 Score 0
01:23 Accepted Answer Score 1
01:42 Thank you

--

Full question
https://stackoverflow.com/questions/3422...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #find #subprocess #raspberrypi2

#avk47



ACCEPTED ANSWER

Score 1


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 will do what you want:

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



ANSWER 2

Score 0


Since you are using the shell=True you can use the following:

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

Try to avoid use of wildcards if possible, and just change your current working directory before searching for your target file.