I'm trying to use a "python loop through list" and execute a command on each line from the list found and in between sleep to give it time to finish that command.
Here my script. I know it's the basic, but some one can help me to help me in put this script together. I'm using an old server with python 2.4 so I cannot use check_out or subprocess.

import os
import sys
import time 


for line in f:
      os.system(/usr/local/sbin/script) + line
     time.sleep(5) # delays for 5 seconds    

Recommended Answers

All 3 Replies

You could download subprocess.py from the python 2.7 distribution and try to use its methods. If your server is a linux server, it may work.

Command you has to be string and you concatenate "line" inside os.system().
So if i have i list of words and want to now lenght of each word,
i can use linux command expr length.
The command get executed on each line of words.txt.

import os
import time

f = open('words.txt')
for line in f:
    line = line.strip()
    os.system('expr length ' + line)

Thanks that works. I was not sure how to concatenate the list with with command.


Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.