Skip to content Skip to sidebar Skip to footer

Implementation Of The Linux Find Command In Python

Can someone point me to a set of instructions of how to actually implement and utilize the find command within a Python script? I have looked at: https://docs.python.org/2/librar

Solution 1:

You probably want to use the check_output() helper function.

find_output = subprocess.check_output('find ~', shell = True)

In the above example, find_output will contain a bytes instance of the find commands stdout. If you wish to capture the stderr as well, add stderr=subprocess.STDOUT as a keyword argument.

Solution 2:

How about this,

found = subprocess.Popen(['find', '.'],stdout=subprocess.PIPE)
for line in iter(found.stdout.readline, ''):
   print line,

Post a Comment for "Implementation Of The Linux Find Command In Python"