CygwinThe default Windows command-line interface cmd.exe leaves a lot to be desired in terms of functionality, specially for those people who know or are getting used to Unix/Linux shells. From file completion to command line utilities, Windows has neglected the CLI user in the past. There are alternatives though: Microsoft's recent offering is the Powershell, and from the GNU front there is Cygwin, which I'd like to revisit. Cygwin provides a quite large set of Unix utilities which run on native Windows NT systems, including of course XP and W2K. The Cygwin environment provides a a feature rich run-time system on top of which a multitude of Unix/Linux utilities run, almost as though the underlying OS where a Unix. File I/O, process creation, sockets, etc. are all handled by Windows of course, and processes created under Cygwin's control are limited as to how much memory they can consume, but this can be tuned if need be. File system security is mapped onto Windows, but the semantics are almost as in Unix; the /etc/passwd and /etc/group files exist an are built by the mkpasswd and mkgroup tools respectively. Installation of Cygwin is well documented, and the setup program allows automated installation if desired, so that a single download can be used as installation source for multiple computers. Installation should be performed in a subdirectory (e.g. C:\\cygwin) of the machine and not in its root directory, so as to not risk other tools modifying the Cygwin installation. Furthermore, keeping everything in a single directory eases backup. During initial installation, the user chooses whether to use text or binary modes for files as a default (the handling of line endings in text files: CR/LF or LF only). I myself use binary mode because of interchange with Unix, but if you mainly work with Windows tools you might prefer text mode; see discussion. The power of Cygwin becomes visible when the shell starts; a bash shell provides everything that a Unix/Linux user needs in terms of scripting (do set up easy copy and paste), and Cygwin provides a huge number of tools and packages ported from the Unix environment including, but not limited to, an X11R6 server (although I prefer Xming), Apache, Perl, PostgreSQL ;almost a full LAMP system here... :-) etc. For those who also need server- type daemons, cygserver provides those services too, allowing programs to run independently of a shell. The list of packages available for installation is very impressive. Launching Windows executables from Cygwin is a no-brainer: enter notepad to start the program, and add an ampersand (&) to the command to background it. Cygwin can map file paths to devices with the mount command, and has other special filenames, such as /proc in which information of the underlying Windows system is mapped onto. The Windows registry is mapped onto /proc/registry, enabling programs to easily retrieve information from it:

$ cat /proc/registry/HKEY_CURRENT_USER/Software/SimonTatham/PuTTY/Sessions/home/HostName

The CYGWIN environment variable can be used to customize Cygwin's behavior, with regard to Windows interaction. For example it is possible to force Cygwin to create Windows shortcuts when it wants to create a symbolic link. Most defaults should be ok for most users, at least I've never had to change any. Cygwin also supplies a programming environment, consisting of the GCC compiler collection with debugger, etc. This tool chain can also be used to build programs that have access to standard Windows 32-bit API including the GUI functions. When combining this tool chain cleverly with MinGW, Cygwin can then be used to create native Windows executables which run without the Cygwin DLLs. This build environment makes it a snap to install a number of other Unix/Linux tools from source: the ubiquitious

$ tar xvzf package.tar.gz
$ cd package
$ ./configure
$ make
$ make install

often works out of the box, including a build of MySQL. If you need to work with Windows and miss the Unix/Linux tools there, I strongly recommend you have a closer look at Cygwin and its good documentation.

Flattr this
Exim, Linux, Apache, Database, and CLI :: 19 Aug 2007 :: e-mail


blog comments powered by Disqus