Solved!
In case this may be helpful to anyone, theThe solution for me was to declare an environment in subprocess.run:
env = os.environ.copy()
env["GDAL_DATA"] = "C:\\Program Files\\GDAL\\gdal-data"
env["PATH"] = (
"C:\\GDAL"
+ os.pathsep
+ "C:\\Program Files\\GDAL"
+ os.pathsep
+ "C:\\Program Files\\TauDEM\\TauDEM5Exe")
Then either
subprocess.run([#mpiexecdir,"-n", "#ncores",#PitRemovedir, #DEMdir],shell=True,env=env,stdout=subprocess.PIPE,stderr=subprocess.PIPE,creationflags=subprocess.CREATE_NO_WINDOW)
or
subprocess.run([#PitRemovedir, #DEMdir],shell=True,env=env,stdout=subprocess.PIPE,stderr=subprocess.PIPE,creationflags=subprocess.CREATE_NO_WINDOW)
works well.
I had come across some similar solutions, but these did not work for me:
- https://stackoverflow.com/questions/33730231/qgis-python-script-returning-non-zero-exit-status-1
- Problem running shell command with PyQGIS
Furthermore, there is another plugin for QGIS 3 called "drainage" which can be handy. It performs all TauDEM processing as batch.
Cheers,