1

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.

1
  • 1
    Can you post some sample code for the attempt? Commented Sep 18, 2009 at 0:52

3 Answers 3

3

You can change the current directory of your script with os.chdir(). You can also set environment variables with os.environ

Sign up to request clarification or add additional context in comments.

Comments

1

Use the subprocess module, and use the cwd argument to set the child's working directory.

Comments

1

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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.