Suppose there's an executable and a Python script to launch it, and they're located in 'sibling' subdirectories, e.g.
/tmp/subdir1/myexecutable
/tmp/subdir2/myscript.py
If in /tmp
and running python subdir2/myscript.py
with a relative path to executable
# myscript.py
from subprocess import Popen
proc = Popen(["../subdir1/myexecutable"])
It makes OSError: [Errno 2] No such file or directory
.
How does the Python search for the executable? Does it use the current working directory and/or location of the script? Does it use PATH and/or PYTHONPATH? Can you change where and how subprocess.Popen
searches for the executable? Are commands, absolute and relative paths for executables treated differently? Are there differences between Linux and Windows? What does shell=True
or shell=False
influence?