1

I want to be able to execute a list of developmental scripts. Something like this:

def scriptRunner(scripts):
    for script in scripts
        import script
        result = script.run()
        # log result

This is a similar question to Python, safe, sandbox, except that the scripts I intend to run will not be malicious. They are development scripts created by other engineers. They may crash, raise exceptions, get stuck in infinite loops -- these sorts of things -- but they won't try to execute rm -rf.

Is there a framework I can put around the script runner so that these conditions are handled and it just logs it and moves on to the next script?

Community
  • 1
  • 1
MikeTwo
  • 1,228
  • 1
  • 14
  • 13

1 Answers1

0

You can use __import__

for script in scripts:
    __import__(script,  globals(), locals(), ['run'], -1)
    result = run()
    # log result
Dr.Tower
  • 985
  • 5
  • 11