I have a nice bash script that works fine and its task is to extract information from several netcdf files and edit other files with that information. So, it is huge and works fine but I need to embed it into another Python script. I read another post Execute shell script on cygwin from Python
But although it works for commands like test, echo, for, do, it says "bash: command not found" for others like cp, sed, or cat.
This is my Python script for that part.
import os, subprocess
os.chdir(r"C:\cygwin64\bin")
cmd = ["bash", "-c", "cd D:/Maria_Eugenia/SOFT/VIEVS_forupdate2/automatic-py; ./ncextract.sh"]
ret = subprocess.call(cmd)
I wouldn't like to move that into python... So, are there any ideas?
PS: the original bash script works well under Cygwin on a Windows PC
Most likely, PATH is not set, or does not include /usr/bin, try this
import os, subprocess
os.chdir(r"C:\cygwin64\bin")
cmd = ["bash", "-c", "PATH=/usr/bin:$PATH; cd D:/Maria_Eugenia/SOFT/VIEVS_forupdate2/automatic-py; ./ncextract.sh"]
ret = subprocess.call(cmd)
You may want to add other directories which contain the binaries you need.
If this still does not fix the issue, consider sourcing you .bashrc like :
import os, subprocess
os.chdir(r"C:\cygwin64\bin")
cmd = ["bash", "-c", "source ~/.bashrc; cd D:/Maria_Eugenia/SOFT/VIEVS_forupdate2/automatic-py; ./ncextract.sh"]
ret = subprocess.call(cmd)