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.

Peter Mortensen
31.3k22 gold badges110 silver badges134 bronze badges
asked Sep 18, 2009 at 0:22
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

answered Sep 18, 2009 at 0:41
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.

answered Sep 18, 2009 at 2:24

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)
answered Sep 4, 2019 at 15:30

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.