I am currently trying to use the following python code to get the number of files within a directory.
output = subprocess.check_output(["adb", "shell", "cd /sdcard/Dir/Subdir", "find . -type f | wc -l"])
/system/bin/sh: cd: too many arguments
find . -type f | wc -l
if you pass arguments to
check_output in a list (not in a string), then if you pass arguments with spaces they will be quoted.
But that's not the main problem here.
adb shell in
check_output, but next commands should be passed through proper command line or standard input of your shell.
You could try the following (untested):
output = subprocess.check_output(["adb", "shell", "cd /sdcard/Dir/Subdir", "&&","find . -type f | wc -l"])
&& tells the shell to chain
find instead of passing all arguments to
or run your shell interactively, and pass the commands like if you typed them (use
Popen for that):
p = subprocess.Popen(["adb", "shell"],stdin=subprocess.PIPE) out,err = p.communicate("cd /sdcard/Dir/Subdir\nfind . -type f | wc -l\n")