473,399 Members | 4,177 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

getting output from a command into a list to work with

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
1 1177
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Hugh Macdonald | last post by:
I'm calling a command from within a python script and I need to be able to both catch the output (stdout and stderr) from it and also have the PID (so that I can kill it) I can do one or other...
16
by: Chris Maloof | last post by:
Hello, Does anyone know how I can read the ASCII text from a console window (from another application) in WinXP? It doesn't sound like a major operation, but although I can find the window via...
0
by: ruju00 | last post by:
I am getting an error in Login() method of the following class FtpConnection public class FtpConnection { public class FtpException : Exception { public FtpException(string message) :...
8
by: lawrence k | last post by:
I've installed Apache 1.3.36 on my Redhat EL 3 machine. Now I'm trying to install PHP 5.1.4. I can not get the ./configure command to work. I keep getting this error: configure: error: Invalid...
2
by: Troels Arvin | last post by:
Hello, I need a way to list an instance's databases, in a way which is easy to parse (I can't count on perl or similar scripting tools to be available everywhere). I know of the 'db2 list...
25
by: Eric | last post by:
Hello, after reading some of the book Programming Python it seems that python is something I would like to delve deeper into. The only thing is, I have no idea what I should try and write. So I was...
1
by: leescriven | last post by:
Hi, Thi is my first post on this forum, and I'm hoping that there is a guru out there who can help me with an annoying problem I am having. I have written a Stored Procedure that relies heavily...
4
by: amjadcsu | last post by:
Hi I am trying to execute a command using os.system. this command lists the number of nodes alive in a cluster. I would like to capture the output in list/array in python. IS it possible.?/ ...
16
by: Okonita via DBMonster.com | last post by:
Hi all, I am comming along with all this Linus/DB2/scripting business...I am no longer scared of it!! (LOL). But, I need to create a .ksh script that does a REORGCHK and output only tables...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.