Invoking Cygwin from Batch/Command Scripts
October 6th, 2013
Writing blog posts - or really anything requiring only basic text formatting - is really nice in Markdown. This blog (at least right now) is running on Octopress, which requires Ruby. Unfortunately, I couldn’t really get it working properly using the Windows build of Ruby.
On top of that, I deploy to a Linux host using Rsync, which doesn’t seem to have any equivalent or port in the Windows side, apart from Cygwin.
I couldn’t figure out how to get shell scripts (.sh files) associated with Cygwin properly and running in the correct folder, so the next-best solution I’ve come up with involves invoking Bash from a .cmd script:
@echo off
set CYGDIR=D:\tools\cygwin
set PATH=%PATH%;%CYGDIR%\bin
FOR /F "tokens=* delims=" %%A IN ('cygpath %~dp0') DO SET CURCYGDIR=%%A
bash --login -c "cd %CURCYGDIR% && do magic bash stuff here"
Almost surprisingly, it works. Also, the DOS/CMD equivalent of Bash’s MYVAR=$(run command here)
is awfully ugly.