By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,100 Members | 2,495 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,100 IT Pros & Developers. It's quick & easy.

getting output from a command into a list to work with

P: n/a
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.
May 21 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Anthony Irwin wrote:
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
May 21 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.