I would like to use relative paths along with subprocess module in order to be able to run different executables.
For getting relative paths and, after reading different threads, I think pathlib module is the best option to do that.
Let assume I have the python script in a particular folder in Windows. Inside it (the previous folder), I have other folders with the executables I want to run. Here it is when subprocess module comes in. However, I do not know how to include the relative paths created with pathlib module into subprocess args field.
From subprocess API I can read that 'args should be a sequence of program arguments or else a single string'.
import pathlib
import subprocess
in_file_1 = pathlib.Path.cwd() / "folder2" / "folder3" / "whatever.exe"
p = subprocess.Popen(str(in_file_1), shell = True)
I would expect to see the whatever.exe process running on the administrator tasks but the process is not started. How can I achieve that? Is there something I am ingoring? Should I just give the relative path from where the python script is saved?
whatever.exelocation? Why do you want to use the current working dir?whatever.exelocation. If I save the python script in the same folder as thewhatever.exethe above code works but If I save it upstreamwhatever.exedoes not work even specifying the relative path to it.pathlib.Path.cwd()so what matters is the current dir when you launch the script, not where the script is located.