Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

cygwin script into python some cmds not working

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

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)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading