p = subprocess.Popen('find . -name [ch]', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) for line in p.stdout.readlines(): q = subprocess.Popen('grep searchstring %s', line, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) print q.stdout.readlines()
- The indentation in line 2 will exclude,
for should be aligned with p above 'grep searchstring %s', line will not replace the string, you need to replace , with %
With these changes and real search values, it works in my OS X box. Final script:
import subprocess p = subprocess.Popen('find . -name *.py', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) for line in p.stdout.readlines(): print line q = subprocess.Popen('grep import %s' % line, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) print q.stdout.readlines()
source share