10.12.2009

Cygwin + Interpreters(Jline) + Carriage return = solved!

I love cygwin. Not only is having every a bash shell and unix utility on windows awesome(grep, less, tail, awk, cut, pipe, sed, du, df, ls, ln, curl, sort, head, vi, X-Server, etc...) but using rxvt or xterm as a replacement to windows cmd window is awesome.

However when I use some command line interpreters such as a groovy shell, maven cli, spring roo, and others, my carriage return doesn't work. When I hit enter, the cursor goes to the next line but the command is not executed. This has been bothering me for months and yesterday I finally found the answer.

The core of the problem is with JLine, a command line API that many Java based interpreters use. Jline queries the environment to see what OS you are running and uses that for the expected end of line input. Because the OS is windows but the terminal is xterm, cygwin (rxvt at least) will not send the command Jline is expecting to signal end of line. Therefore, you can't actually execute anything in the interpreter.

So after searching for a solution over and over I finally stumbled upon this issue. Thank god for JIRA! It ultimately led me to this Jline defect.

So in order to save you a lot of trouble, all you have to do is add the following to your jvm args:
-Djline.terminal=jline.UnixTerminal


If you are doing this for maven CLI, then you need to add the -D argument to your MAVEN_OPTS because Maven will execute the process for you.

I didn't need to use the stty commands as recommended but I only fixed my maven-cli plugin (which is awesome btw). Maybe someone could explain what the stty commands are for and when or why you'd need them.

So hopefully this will save some cygwin users some time and frustration.

No comments:

Post a Comment