Friday, November 05, 2010

Cygwin - Pass commands (parameters) at startup

There is a lot of stuff you will find regarding Cygwin but I was willing to pass some commands to Cygwin from Hudson CI server at start up but no body is telling it in simple way. So lets dive into it:
Step 1. Go to Cygwin installation directory
Step 2. Locate Cygwin.bat and right click and select edit (backup before editing :))
Step 3.
Initial Structure:
@echo off
chdir C:\cygwin\bin
bash --login -i

Add your command as:
bash --login -i -c 'your commands here'
-- To pass more than one command seperate them using ; (semi)
bash --login -i -c 'cd $X;cd $Y;clear;'

You are done :) Oops save the file
Start your Cygwin shell it will pass the commands as expected

If you want to pass some parameters from outside (e.g. Hudson or command prompt) use %1, %2, %3
e.g. from hudson: cygwin 'shashank'
bash --login -i -c 'print %1'

print's shashank in the cygwin shell. Use Hudson Console output window to view.

No comments:

Post a Comment