Skip to content Skip to sidebar Skip to footer

How Do I Execute A Program From Python? Os.system Fails

I want to run a command with os.system but i get an error c:/fe ' is not recognized as an internal or external command, operable program or batch file The code I use is import os

Solution 1:

os.system has some serious drawbacks, especially with space in filenames and w.r.t. security. I suggest you look into the subprocess module and particularly subprocess.check_call, which is much more powerful. You could then do e.g.

import subprocess
subprocess.check_call(["c:\\fe re\\python.exe", "program", etcetc...])

Of course, make sure to take great care not to have user-determined variables in these calls unless the user is already running the script herself from the command line with the same privileges.

Post a Comment for "How Do I Execute A Program From Python? Os.system Fails"