I'm trying to make a Python script run another program from its own path.
I've got the execution of the other program working using os.system, but the program will crash because it cannot find its resources (wrong path, I assume). I tried adding the folder harboring the executable to the path, but that didn't help.
-
1Can you post some sample code for the attempt?Peter Mortensen– Peter Mortensen2009年09月18日 00:52:27 +00:00Commented Sep 18, 2009 at 0:52
3 Answers 3
You can change the current directory of your script with os.chdir(). You can also set environment variables with os.environ
Comments
Use the subprocess module, and use the cwd argument to set the child's working directory.
Comments
These two methods from the os library will do the work:os.chdir and os.system.
path = "C://Program Files//Microsoft SQL Server//Client
SDK//ODBC//130//Tools//Binn//" #make sure to use forward slash
program = "bcp.exe"
os.chdir(path)
os.system(program)