0

I have scripts I would like to execute in sequence with a time delay between the each of them.

The intention is to run the scripts which scan for an string in file names and imports those files into a folder. The time delay is to give the script the time to finish copying the files before moving to the next file.

I have tried the questions already posed on Stackoverflow:

Running multiple Python scripts

Run a python script from another python script, passing in args

But I'm not understanding why the lines below don't work.

import time
import subprocess

subprocess.call(r'C:\Users\User\Documents\get summary into folder.py', shell=True)
time.sleep(100)
subprocess.call(r'C:\Users\User\Documents\get summaries into folder.py', shell=True)
time.sleep(100)

The script opens the files but doesn't run.

1
  • 1
    You have to call it the same way you initialize python from the command line. py C:\Users\User\Documents\get summary into folder.py (or the python command depending on how you have it configured. Commented Nov 2, 2017 at 14:50

1 Answer 1

1

Couple of things, first of all, time.sleep accepts seconds as an argument, so you're waiting 100s after you've spawned these 2 processes, I guess you meant .100. Anyway, if you just want to run synchronously your 2 scripts better use subprocess.Popen.wait, that way you won't have to wait more than necessary, example below:

import time
import subprocess

test_cmd = "".join([
    "import time;",
    "print('starting script{}...');",
    "time.sleep(1);",
    "print('script{} done.')"
])

for i in range(2):
    subprocess.Popen(
        ["python", "-c", test_cmd.format(*[str(i)] * 2)], shell=True).wait()
    print('-'*80)
Sign up to request clarification or add additional context in comments.

1 Comment

Hi, Thanks for that. I am a bit of a newbie though; where do the file destinations go in your example?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.