0

I've seen a few questions similar to this one, but none that really help my particular situation. I have a script that loops through a directory of text files, each of which has one one-line script command in it which needs to be run through command prompt. The basic layout is as follows:

for _, _, files in os.walk(my_directory):
  for f in files:
    fo = open(my_directory + f, 'r')
    command = fo.readlines()
    os.system(command)
    #rest of the code...

When I test this with only one file it works fine, but when I do them all together in the directory, they seem to stop at random points in each command. I think it's because they overlap and don't have time to finish (the specific command is a fairly long process to run, about 2 minutes each). How can I make sure each os.system call runs through in its entirety before moving on to the next?

thnkwthprtls
  • 3,287
  • 11
  • 42
  • 63
  • os.system will not continue until the command completes... so overlapping commands is not your problem – Joran Beasley Sep 24 '13 at 18:19
  • I didn't think it does, however when I added a print statement to check and it's passing the commands into os.system() correctly, and when I enter the files' commands directly into CMD they all work. Is it possibly they're taking to long and timing out or something? – thnkwthprtls Sep 24 '13 at 18:23
  • I suspect the problem is that readlines returns a list ... os.system is not expecting a list ... try something like `for cmd in command: os.system(cmd)` – Joran Beasley Sep 24 '13 at 18:48

1 Answers1

1

os.system will not continue until the command completes... so overlapping commands is not your problem

I suspect the problem is that readlines returns a list ... os.system is not expecting a list ... try something like

for cmd in command: os.system(cmd)
Joran Beasley
  • 110,522
  • 12
  • 160
  • 179