getting output from a command into a list to work with

A

Anthony Irwin

Hi All,

I would like to run the command below and have each line from the
output stored as an element in a list.

find /some/path/ -maxdepth 1 -type f -size +100000k -exec ls -1 '{}' \

The reason for this is so I can then work on each file in the
following manner

var = command

for i in var:
# do stuff to file code here

not sure the best way to get the output of the command so each line of
output is one element in the list.

--
Kind Regards,
Anthony Irwin

http://www.irwinresources.com
http://www.makehomebusiness.com
email: anthony at above domains, - www.
 
P

Peter Otten

Anthony said:
I would like to run the command below and have each line from the
output stored as an element in a list.

find /some/path/ -maxdepth 1 -type f -size +100000k -exec ls -1 '{}' \

The reason for this is so I can then work on each file in the
following manner

var = command

for i in var:
# do stuff to file code here

not sure the best way to get the output of the command so each line of
output is one element in the list.


from subprocess import Popen, PIPE

for line in Popen("find ...", shell=True, stdout=PIPE).stdout:
# do stuff

or if you don't need shell expansion

for line in Popen(["find", "/some/path", ...], stdout=PIPE).stdout:
# do stuff

See http://docs.python.org/lib/module-subprocess.html for more.

Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top