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
C:
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)
example:
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.

Tuesday, October 12, 2010

Java! What the Hell (No Support for Unsigned) (UTF-8 Encoding Bug)

Recently I got some work again in Java and it's around 5 years back when I last developed any application in Java. A lot of changes are here but I got a lot of issues with Java after coming from C#. In two worlds 'Java Sucks' if you are coming from C#. This was not the thought for me when I switched from Java to C#.

Why?

1. I required to deal with a lot with the binary data that has unsigned bytes but woh ho Java doesn't support unsigned int, unsigned byte. On asking one of my Java colleague (he loves java and hates C# as most of the people from Java background do) he said are you programming for some ancient age. Now no body uses unsigned things. What the solution this is? However wrote a tiny library to solve it. If you require it just drop me a mail I can send it.

2. Java Encoding Issue (UTF-8 with BOM): Java has a bug in the bug database from Sep-2001 that has been closed with no-fix and the reasoning behind it is:

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4508058

"
The assumption we made to implement this RFE is that the change would not
break existing real world application, this assumption is obvious
not true, see #6378911. We decided to back out the change we've made
and closed this RFE as "will not fix", for compatibility reason.
Posted Date : 2006-02-18 02:33:09.0
"

What are you talking about?
I got some C# files that were getting laxically analyzed and parsed using ANTLR 3.2 in a Linux system using Java. And what I got an out of memory exception (heap out of space). What the hell I did. I am loading a 4kb file and its going out of memory. It was the encoding issue. However I managed to get the resolution here:
http://koti.mbnet.fi/akini/java/unicodereader/

Now I think C# is much more richer and friendly language than Java.

Please don't mind it and take personally if you love Java and I am not here to remark on any language capabilities but its my personal choice to work with C#.