-1

So I am trying to write a tool where I select a group of files, pretty simple, and then take code from a text box and apply that code to the files in the list, less simple.

I'm not sure what the best way to try and execute this code would be. I feel like trying to read it in as a string would be more trouble than it is worth and I don't really want to just pop out a command line window. Is there any precedent that someone could point me to that would help me out with this? I've never tried to allow for on the fly adaptability like this I generally always hard code what the application should do ahead of time.

Thanks.

  • 1
    Possibly a duplicates of :http://stackoverflow.com/questions/701802/how-do-i-execute-a-string-containing-python-code-in-python. – Quinn Feb 05 '16 at 02:06

1 Answers1

-1

I don't know how you can execute code without reading it first. :)

If it's python code, just read it in as a string and feed it to exec()

If it's a shell script, you're better off writing it to a temp file and then running it with subprocess.Popen()

Brendan Abel
  • 35,343
  • 14
  • 88
  • 118