Python Forum

Full Version: Running script with subprocess in another directory
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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()
Finally the following seems to work adding cwd

RunScrip = subprocess.Popen(['sh', MyScrip ], cwd = NewPath)