Logging into Cygwin and executing commands using bat file in windows

batch-filecygwinmakefile

I am using windows XP operating system and cygwin is installed in my C drive.

I need to login to cygwin directly to my directory path which contains a makefile and also a bash script called build.sh in the same directory. So i modified the original cygwin.bat file and added the line as shown below.

@echo off

C:
chdir C:\cygwin\bin

bash --login "/cygdrive/E/scheme_31july/build/build.sh"

When i double click on this bat file i could see my script executing but not on cygwin shell but on windows cmd shell as a result I get errors for "make" command like "No rule to make target" as make comes bundled with cygwin.

And when I explicitly login to cygwin using default cygwin.bat file and execute my script by giving following commands in cygwin shell the script executes without errors.

Basically I want to write a bat file so that I can keep it anywhere in my PC and instead of manually openeing the cygwin prompt and typing commands like:

$ cd /cygdrive/E/scheme_31july/build/
$ sh build.sh

it should happen automatically. I sit possible to do so.

Regards,
Harshit

Best Answer

No rule to make target sounds more like make being executed in the wrong directory. make itself seems to be available and running as intended.

Try this:

bash --login -c "cd /cygdrive/E/scheme_31july/build/ && sh build.sh"

This should start a --login session (which should give you access to all the settings and tools you'd expect in a cygwin prompt environment), then execute the given shell command, which is the cd and sh you asked for. You could also write those two lines to a separate script file, and pass the name of that to bash instead of the full path to build.sh.

You could also try to cd into C:\scheme_31july\build in the bat file and then execute bash from there. Not sure whether bash will try to change path upon entering the login session. You can try whether things work without the --login, both for this approach and the one above.

@echo off
C:
cd C:\scheme_31july\build
C:\cygwin\bin\bash.exe ./build.sh

I'm not sure whether you want the session to turn interactive after that or not. In the above case, bash will terminate after the script completed, and might even close the window. You might have to add a read into build.sh to avoid that. If you want bash to turn interactive after executing some command, you can try using the --rcfile option of bash to execute some commands and then turn interactive.

Related Topic