0

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.
Thanks

import os
import sys
import time 

f=open('nserver.txt')

for line in f:
      os.system(/usr/local/sbin/script) + line
     time.sleep(5) # delays for 5 seconds    
f.close()
3
Contributors
3
Replies
29
Views
1 Year
Discussion Span
Last Post by pirulo64
0

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.

1

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()
    time.sleep(5)
    os.system('expr length ' + line)
f.close()    

Edited by snippsat

0

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

Pirulo

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.