1 <sect1 id="using-effectively">
2 <title>Using Cygwin effectively with Windows</title>
5 Cygwin is not a full operating system, and so must rely on Windows for
6 accomplishing some tasks. For example, Cygwin provides a POSIX view
7 of the Windows filesystem, but does not provide filesystem drivers of
8 its own. Therefore part of using Cygwin effectively is learning to use
10 Many Windows utilities provide a good way to interact with Cygwin's
11 predominately command-line environment. For example,
12 <command>ipconfig.exe</command> provides information about network
13 configuration, and <command>net.exe</command> views and configures
14 network file and printer resources. Most of these tools
15 support the <literal>/?</literal> switch to display usage information.
19 Unfortunately, no standard set of tools included with all versions of
20 Windows exists. If you are unfamiliar with the tools available
21 on your system, here is a general guide. Windows NT 4.0 has only a basic
22 set of tools, which later versions of Windows expanded.
23 Microsoft also provides free downloads for Windows NT 4.0 (the Resource Kit
24 Support Tools), Windows 2000 (the Resource Kit Tools), and XP (the
25 Windows Support Tools). Generally, the younger the Windows version, the
26 more complete are the on-board tools. Additionally, many independent sites
28 <ulink url="http://download.com">download.com</ulink>,
29 <ulink url="http://simtel.net">simtel.net</ulink>,
31 <ulink url="http://technet.microsoft.com/en-us/sysinternals/default.aspx">Sysinternals</ulink>
32 provide quite useful command-line utilities, as far as they are not
33 already provided by Cygwin. A few Windows tools, such as
34 <command>find.exe</command>, <command>link.exe</command> and
35 <command>sort.exe</command>, may conflict with the Cygwin versions
36 make sure that you use the full path (<command>/usr/bin/find</command>)
37 or that your Cygwin <literal>bin</literal> directory comes first in your
41 <sect2 id="using-pathnames-effectively"> <title>Pathnames</title>
44 Windows programs do not understand POSIX pathnames, so any arguments
45 that reference the filesystem must be in Windows (or DOS) format or
46 translated. Cygwin provides the <command>cygpath</command> utility for
47 converting between Windows and POSIX paths. A complete description of its
48 options and examples of its usage are in <xref linkend="cygpath"></xref>,
49 including a shell script for starting Windows Explorer in any directory.
50 The same format works for most Windows programs, for example
52 <literal>notepad.exe "$(cygpath -aw "Desktop/Phone Numbers.txt")"</literal>
54 A few programs require a Windows-style, semicolon-delimited path list,
55 which <command>cygpath</command> can translate from a POSIX path with the
56 <literal>-p</literal> option. For example, a Java compilation from
57 <command>bash</command> might look like this:
59 <literal>javac -cp "$(cygpath -pw "$CLASSPATH")" hello.java</literal>
61 Since using quoting and subshells is somewhat awkward, it is often
62 preferable to use <command>cygpath</command> in shell scripts.
67 <sect2 id="using-console"> <title>Console Programs</title>
69 Another issue is receiving output from or giving input to console-based
70 Windows programs. Unfortunately, interacting with Windows console
71 applications is not a simple matter of using a translation utility. Windows
72 console applications are designed to run under
73 <command>cmd.exe</command>, and some do not deal gracefully with other
74 situations. Cygwin can receive console input only if it
75 is also running in a console window since Windows does not provide
76 any way to attach to the backend of the console device. Another
77 traditional Unix input/output method, ptys (pseudo-terminals), is
78 supported by Cygwin but not entirely by Windows. The basic problem is
79 that a Cygwin pty is a pipe and some Windows applications do not like
80 having their input or output redirected to pipes.
84 To help deal with these issues, Cygwin supports customizable levels of
85 Windows versus Unix compatibility behavior. To be most compatible with
86 Windows programs, use a DOS prompt, running only the occasional Cygwin
87 command or script. Next would be to run <command>bash</command> within
88 a default DOS box. To make Cygwin more Unix compatible in this case,
89 set <envar>CYGWIN=tty</envar> (see <xref linkend="using-cygwinenv"></xref>).
90 Alternatively, the optional <systemitem>mintty</systemitem> package
91 provides a terminal emulator similar to such X11 programs as
92 <command>xterm</command> (it is not necessary to set
93 <envar>CYGWIN=tty</envar> with <command>mintty</command> nor is it
94 necessary to be running <systemitem>/Cygwin/X</systemitem>). Using
95 <command>mintty.exe</command> provides the most Unix-like environment,
96 but expect some compatibility problems with Windows programs.
101 <sect2 id="using-net"> <title>Cygwin and Windows Networking</title>
103 Many popular Cygwin packages, such as <systemitem>ncftp</systemitem>,
104 <systemitem>lynx</systemitem>, and <systemitem>wget</systemitem>, require a
105 network connection. Since Cygwin relies on Windows for connectivity,
106 if one of these tools is not working as expected you may need to
107 troubleshoot using Windows tools. The first test is to see if you
108 can reach the URL's host with <command>ping.exe</command>, one of the
109 few utilities included with every Windows version since Windows 95.
110 If you chose to install the <systemitem>inetutils</systemitem> package,
112 Windows and Cygwin versions of utilities such as <command>ftp</command>
113 and <command>telnet</command>. If you are having problems using one
114 of these programs, see if the alternate one works as expected.
118 There are a variety of other programs available for specific situations.
119 If your system does not have an always-on network connection, you
120 may be interested in <command>rasdial.exe</command> for automating dialup
122 Users who frequently change their network
123 configuration can script these changes with <command>netsh.exe</command>
124 (Windows 2000 and later). For proxy users, the open source
125 <ulink url="http://apserver.sourceforge.net">
126 NTLM Authorization Proxy Server</ulink> or the no-charge
127 <ulink url="http://www.hummingbird.com/products/nc/socks/index.html">
128 Hummingbird SOCKS Proxy</ulink> may allow you to use Cygwin network
129 programs in your environment.
134 <sect2 id="using-cygutils"><title>The cygutils package</title>
137 The optional <systemitem>cygutils</systemitem> package contains
138 miscellaneous tools that are small enough to not require their own package.
139 It is not included in a default Cygwin install; select it from the Utils
140 category in <command>setup.exe</command>. Several of the
141 <systemitem>cygutils</systemitem> tools are useful for interacting with
145 One of the hassles of Unix-Windows interoperability is the different line
146 endings on text files. As mentioned in <xref linkend="using-textbinary"></xref>,
147 Unix tools such as <command>tr</command> can convert between CRLF and LF
148 endings, but <systemitem>cygutils</systemitem> provides several dedicated programs:
149 <command>conv</command>, <command>d2u</command>, <command>dos2unix</command>,
150 <command>u2d</command>, and <command>unix2dos</command>. Use the
151 <literal>--help</literal> switch for usage information.
155 <sect2 id="using-shortcuts"><title>Creating shortcuts with cygutils</title>
157 Another problem area is between Unix-style links, which link one file
158 to another, and Microsoft .lnk files, which provide a shortcut to a
159 file. They seem similar at first glance but, in reality, are fairly
160 different. By default, Cygwin does not create symlinks as .lnk files,
161 but there's an option to do that, see <xref linkend="using-cygwinenv"></xref>.
162 These symlink .lnk files are compatible with Windows-created .lnk files,
163 but they are still different. They do not include much of the information
164 that is available in a standard Microsoft shortcut, such as the working
165 directory, an icon, etc. The <systemitem>cygutils</systemitem>
166 package includes a <command>mkshortcut</command> utility for creating
167 standard native Microsoft .lnk files.
171 But here's the problem. If Cygwin handled these native shortcuts like any
172 other symlink, you could not archive Microsoft .lnk files into
173 <command>tar</command> archives and keep all the information in them.
174 After unpacking, these shortcuts would have lost all the extra information
175 and would be no different than standard Cygwin symlinks. Therefore these two
176 types of links are treated differently. Unfortunately, this means that the
177 usual Unix way of creating and using symlinks does not work with native
182 <sect2 id="using-printing"><title>Printing with cygutils</title>
184 There are several options for printing from Cygwin, including the
185 <command>lpr</command> found in <systemitem>cygutils</systemitem> (not to be confused with the
186 native Windows <command>lpr.exe</command>). The easiest way to use <systemitem>cygutils</systemitem>'
187 <command>lpr</command> is to specify a default device name in the
188 <envar>PRINTER</envar> environment variable. You may also specify a device
189 on the command line with the <literal>-d</literal> or <literal>-P</literal>
190 options, which will override the environment variable setting.
195 may be a UNC path (<literal>\\server_name\printer_name</literal>), a reserved
196 DOS device name (<literal>prn</literal>, <literal>lpt1</literal>), or a
197 local port name that is mapped to a printer share. Note that forward slashes
198 may be used in a UNC path (<literal>//server_name/printer_name</literal>),
199 which is helpful when using <command>lpr</command> from a shell that uses
200 the backslash as an escape character.
204 <command>lpr</command> sends raw data to the printer; no formatting is done.
205 Many, but not all, printers accept plain text as input. If your printer
206 supports PostScript, packages such as
207 <systemitem>a2ps</systemitem> and <systemitem>enscript</systemitem> can prepare
208 text files for printing. The <systemitem>ghostscript</systemitem> package also
209 provides some translation
210 from PostScript to various native printer languages. Additionally, a native
211 Windows application for printing PostScript, <command>gsprint</command>, is
212 available from the <ulink url="http://www.cs.wisc.edu/~ghost/">Ghostscript