0

I have an executable that pulls an image off of a camera and saves it to the current directory.

I have a python application that calls this executable. Which is located in a different directory.

What i would like to do is have the python program call the executable, and the executable to run in the current directory that it is in rather than the same directory that the python program is running in.

Is this possible?

Ben B
  • 3
  • 3

1 Answers1

5

Yes, simply pass the cwd parameter to any of the subprocess APIs to set the current working directory.

If cwd is not None, the child’s current directory will be changed to cwd before it is executed. Note that this directory is not considered when searching the executable, so you can’t specify the program’s path relative to cwd.

E.g.

import subprocess

subprocess.call(['/path/to/prog', 'arg'], cwd=some_dir)
Jonathon Reinhart
  • 116,671
  • 27
  • 221
  • 298
  • saved my day, thank you. In my case I used: subprocess.Popen(full_path, cwd=exe_directory) – Ruben Sep 21 '20 at 10:37