Running script with subprocess in another directory - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Running script with subprocess in another directory (/thread-39247.html) |
Running script with subprocess in another directory - paul18fr - Jan-20-2023 Hi, I'm trying to run an executable script (thanks to chmod +x) but located in another directory; whatever I do, it is running in the current directory i.e. where the python file is: what am i missing? I've chosen suprocess.Popen +wait() to be sure all the script has been run prior doing anything else.Thanks for your comments and advices Paul MyScrip = 'Script.sh' # chmod +x Script.sh RunScrip = subprocess.Popen(['sh', NewPath + '/' + MyScrip ]) RunScrip.wait() RE: Running script with subprocess in another directory - paul18fr - Jan-20-2023 Finally the following seems to work adding cwd RunScrip = subprocess.Popen(['sh', MyScrip ], cwd = NewPath) |