Reputation: 19112
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.
Upvotes: 1
Views: 4460
Reputation: 11
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)
Upvotes: 1
Reputation: 12339
Use the subprocess module, and use the cwd
argument to set the child's working directory.
Upvotes: 1
Reputation: 375594
You can change the current directory of your script with os.chdir
(). You can also set environment variables with os.environ
Upvotes: 3