2003-07-31 23:06:55 +02:00
|
|
|
<sect1 id="using-effectively">
|
|
|
|
<title>Using Cygwin effectively with Windows</title>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
Cygwin is not a full operating system, and so must rely on Windows for
|
|
|
|
accomplishing some tasks. For example, Cygwin provides a POSIX view
|
|
|
|
of the Windows filesystem, but does not provide filesystem drivers of
|
|
|
|
its own. Therefore part of using Cygwin effectively is learning to use
|
|
|
|
Windows effectively.
|
|
|
|
Many Windows utilities provide a good way to interact with Cygwin's
|
|
|
|
predominately command-line environment. For example,
|
|
|
|
<command>ipconfig.exe</command> provides information about network
|
|
|
|
configuration, and <command>net.exe</command> views and configures
|
|
|
|
network file and printer resources. Most of these tools
|
|
|
|
support the <literal>/?</literal> switch to display usage information.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
Unfortunately, no standard set of tools included with all versions of
|
|
|
|
Windows exists. If you are unfamiliar with the tools available
|
2008-07-17 13:49:45 +02:00
|
|
|
on your system, here is a general guide. Windows NT 4.0 has only a basic
|
|
|
|
set of tools, which later versions of Windows expanded.
|
2003-07-31 23:06:55 +02:00
|
|
|
Microsoft also provides free downloads for Windows NT 4.0 (the Resource Kit
|
|
|
|
Support Tools), Windows 2000 (the Resource Kit Tools), and XP (the
|
2008-07-17 13:49:45 +02:00
|
|
|
Windows Support Tools). Generally, the younger the Windows version, the
|
|
|
|
more complete are the on-board tools. Additionally, many independent sites
|
|
|
|
such as
|
|
|
|
<ulink url="http://download.com">download.com</ulink>,
|
2004-12-24 22:58:38 +01:00
|
|
|
<ulink url="http://simtel.net">simtel.net</ulink>,
|
2008-07-17 13:49:45 +02:00
|
|
|
and Microsoft's own
|
|
|
|
<ulink url="http://technet.microsoft.com/en-us/sysinternals/default.aspx">Sysinternals</ulink>
|
|
|
|
provide quite useful command-line utilities, as far as they are not
|
|
|
|
already provided by Cygwin. A few Windows tools, such as
|
|
|
|
<command>find.exe</command>, <command>link.exe</command> and
|
|
|
|
<command>sort.exe</command>, may conflict with the Cygwin versions
|
|
|
|
make sure that you use the full path (<command>/usr/bin/find</command>)
|
|
|
|
or that your Cygwin <literal>bin</literal> directory comes first in your
|
|
|
|
<envar>PATH</envar>.
|
2003-07-31 23:06:55 +02:00
|
|
|
</para>
|
|
|
|
|
2008-07-17 13:49:45 +02:00
|
|
|
<sect2 id="using-pathnames-effectively"> <title>Pathnames</title>
|
2003-07-31 23:06:55 +02:00
|
|
|
|
|
|
|
<para>
|
|
|
|
Windows programs do not understand POSIX pathnames, so any arguments
|
|
|
|
that reference the filesystem must be in Windows (or DOS) format or
|
|
|
|
translated. Cygwin provides the <command>cygpath</command> utility for
|
|
|
|
converting between Windows and POSIX paths. A complete description of its
|
2004-12-24 22:58:38 +01:00
|
|
|
options and examples of its usage are in <xref linkend="cygpath"></xref>,
|
2003-07-31 23:06:55 +02:00
|
|
|
including a shell script for starting Windows Explorer in any directory.
|
|
|
|
The same format works for most Windows programs, for example
|
|
|
|
<screen>
|
|
|
|
<literal>notepad.exe "$(cygpath -aw "Desktop/Phone Numbers.txt")"</literal>
|
|
|
|
</screen>
|
|
|
|
A few programs require a Windows-style, semicolon-delimited path list,
|
|
|
|
which <command>cygpath</command> can translate from a POSIX path with the
|
|
|
|
<literal>-p</literal> option. For example, a Java compilation from
|
|
|
|
<command>bash</command> might look like this:
|
|
|
|
<screen>
|
|
|
|
<literal>javac -cp "$(cygpath -pw "$CLASSPATH")" hello.java</literal>
|
|
|
|
</screen>
|
|
|
|
Since using quoting and subshells is somewhat awkward, it is often
|
|
|
|
preferable to use <command>cygpath</command> in shell scripts.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
</sect2>
|
|
|
|
|
2008-07-17 13:49:45 +02:00
|
|
|
<sect2 id="using-console"> <title>Console Programs</title>
|
2003-07-31 23:06:55 +02:00
|
|
|
<para>
|
2008-06-27 02:34:02 +02:00
|
|
|
Another issue is receiving output from or giving input to console-based
|
2003-07-31 23:06:55 +02:00
|
|
|
Windows programs. Unfortunately, interacting with Windows console
|
|
|
|
applications is not a simple matter of using a translation utility. Windows
|
2008-07-17 13:49:45 +02:00
|
|
|
console applications are designed to run under
|
|
|
|
<command>cmd.exe</command>, and some do not deal gracefully with other
|
2003-07-31 23:06:55 +02:00
|
|
|
situations. Cygwin can receive console input only if it
|
2008-07-17 13:49:45 +02:00
|
|
|
is also running in a console window since Windows does not provide
|
2003-07-31 23:06:55 +02:00
|
|
|
any way to attach to the backend of the console device. Another
|
2008-06-27 02:34:02 +02:00
|
|
|
traditional Unix input/output method, ptys (pseudo-terminals), is
|
2003-07-31 23:06:55 +02:00
|
|
|
supported by Cygwin but not entirely by Windows. The basic problem is
|
|
|
|
that a Cygwin pty is a pipe and some Windows applications do not like
|
|
|
|
having their input or output redirected to pipes.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
To help deal with these issues, Cygwin supports customizable levels of
|
2008-07-17 13:49:45 +02:00
|
|
|
Windows versus Unix compatibility behavior. To be most compatible with
|
2003-07-31 23:06:55 +02:00
|
|
|
Windows programs, use a DOS prompt, running only the occasional Cygwin
|
2008-06-27 02:34:02 +02:00
|
|
|
command or script. Next would be to run <command>bash</command> within
|
|
|
|
a default DOS box. To make Cygwin more Unix compatible in this case,
|
2004-12-24 22:58:38 +01:00
|
|
|
set <envar>CYGWIN=tty</envar> (see <xref linkend="using-cygwinenv"></xref>).
|
2004-01-11 09:32:09 +01:00
|
|
|
Alternatively, the optional <systemitem>rxvt</systemitem> package provides
|
2003-07-31 23:06:55 +02:00
|
|
|
a native-Windows version of the popular X11 terminal emulator (it is not
|
2004-12-24 22:58:38 +01:00
|
|
|
necessary to set <envar>CYGWIN=tty</envar> with <command>rxvt</command>).
|
2003-07-31 23:06:55 +02:00
|
|
|
Using <command>rxvt.exe</command> provides the most Unix-like environment,
|
|
|
|
but expect some compatibility problems with Windows programs.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
</sect2>
|
|
|
|
|
2008-07-17 13:49:45 +02:00
|
|
|
<sect2 id="using-net"> <title>Cygwin and Windows Networking</title>
|
2003-07-31 23:06:55 +02:00
|
|
|
<para>
|
2004-01-11 09:32:09 +01:00
|
|
|
Many popular Cygwin packages, such as <systemitem>ncftp</systemitem>,
|
|
|
|
<systemitem>lynx</systemitem>, and <systemitem>wget</systemitem>, require a
|
2003-07-31 23:06:55 +02:00
|
|
|
network connection. Since Cygwin relies on Windows for connectivity,
|
|
|
|
if one of these tools is not working as expected you may need to
|
|
|
|
troubleshoot using Windows tools. The first test is to see if you
|
|
|
|
can reach the URL's host with <command>ping.exe</command>, one of the
|
|
|
|
few utilities included with every Windows version since Windows 95.
|
2004-01-11 09:32:09 +01:00
|
|
|
If you chose to install the <systemitem>inetutils</systemitem> package,
|
|
|
|
you may have both
|
2003-07-31 23:06:55 +02:00
|
|
|
Windows and Cygwin versions of utilities such as <command>ftp</command>
|
|
|
|
and <command>telnet</command>. If you are having problems using one
|
|
|
|
of these programs, see if the alternate one works as expected.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
There are a variety of other programs available for specific situations.
|
|
|
|
If your system does not have an always-on network connection, you
|
2008-07-17 13:49:45 +02:00
|
|
|
may be interested in <command>rasdial.exe</command> for automating dialup
|
|
|
|
connections.
|
2003-07-31 23:06:55 +02:00
|
|
|
Users who frequently change their network
|
|
|
|
configuration can script these changes with <command>netsh.exe</command>
|
2008-07-17 13:49:45 +02:00
|
|
|
(Windows 2000 and later). For proxy users, the open source
|
2004-12-24 22:58:38 +01:00
|
|
|
<ulink url="http://apserver.sourceforge.net">
|
2003-07-31 23:06:55 +02:00
|
|
|
NTLM Authorization Proxy Server</ulink> or the no-charge
|
2004-12-24 22:58:38 +01:00
|
|
|
<ulink url="http://www.hummingbird.com/products/nc/socks/index.html">
|
2003-07-31 23:06:55 +02:00
|
|
|
Hummingbird SOCKS Proxy</ulink> may allow you to use Cygwin network
|
|
|
|
programs in your environment.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
</sect2>
|
|
|
|
|
2008-07-17 13:49:45 +02:00
|
|
|
<sect2 id="using-cygutils"><title>The cygutils package</title>
|
2003-07-31 23:06:55 +02:00
|
|
|
|
|
|
|
<para>
|
2008-07-17 13:49:45 +02:00
|
|
|
The optional <systemitem>cygutils</systemitem> package contains
|
|
|
|
miscellaneous tools that are small enough to not require their own package.
|
|
|
|
It is not included in a default Cygwin install; select it from the Utils
|
|
|
|
category in <command>setup.exe</command>. Several of the
|
|
|
|
<systemitem>cygutils</systemitem> tools are useful for interacting with
|
|
|
|
Windows.</para>
|
2003-07-31 23:06:55 +02:00
|
|
|
|
|
|
|
<para>
|
|
|
|
One of the hassles of Unix-Windows interoperability is the different line
|
2004-12-24 22:58:38 +01:00
|
|
|
endings on text files. As mentioned in <xref linkend="using-textbinary"></xref>,
|
2003-07-31 23:06:55 +02:00
|
|
|
Unix tools such as <command>tr</command> can convert between CRLF and LF
|
2004-01-11 09:32:09 +01:00
|
|
|
endings, but <systemitem>cygutils</systemitem> provides several dedicated programs:
|
2003-07-31 23:06:55 +02:00
|
|
|
<command>conv</command>, <command>d2u</command>, <command>dos2unix</command>,
|
|
|
|
<command>u2d</command>, and <command>unix2dos</command>. Use the
|
|
|
|
<literal>--help</literal> switch for usage information.
|
|
|
|
</para>
|
2004-01-24 09:09:45 +01:00
|
|
|
</sect2>
|
2003-07-31 23:06:55 +02:00
|
|
|
|
2008-07-17 13:49:45 +02:00
|
|
|
<sect2 id="using-shortcuts"><title>Creating shortcuts with cygutils</title>
|
2003-07-31 23:06:55 +02:00
|
|
|
<para>
|
|
|
|
Another problem area is between Unix-style links, which link one file
|
|
|
|
to another, and Microsoft .lnk files, which provide a shortcut to a
|
|
|
|
file. They seem similar at first glance but, in reality, are fairly
|
|
|
|
different. By default, Cygwin uses a mechanism that creates symbolic
|
|
|
|
links that are compatible with standard Microsoft .lnk files. However,
|
|
|
|
they do not include much of the information that is available in a
|
|
|
|
standard Microsoft shortcut, such as the working directory, an icon,
|
2004-01-11 09:32:09 +01:00
|
|
|
etc. The <systemitem>cygutils</systemitem> package includes a
|
|
|
|
<command>mkshortcut</command>
|
2003-07-31 23:06:55 +02:00
|
|
|
utility for creating standard Microsoft .lnk files.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
If Cygwin handled these native shortcuts like any other symlink,
|
|
|
|
you could not archive Microsoft .lnk files into <command>tar</command>
|
|
|
|
archives and keep all the information in them. After unpacking,
|
|
|
|
these shortcuts would have lost all the extra information and would
|
|
|
|
be no different than standard Cygwin symlinks. Therefore these two types
|
|
|
|
of links are treated differently. Unfortunately, this means that the
|
|
|
|
usual Unix way of creating and using symlinks does not work with
|
|
|
|
Windows shortcuts.
|
|
|
|
</para>
|
|
|
|
</sect2>
|
|
|
|
|
2008-07-17 13:49:45 +02:00
|
|
|
<sect2 id="using-printing"><title>Printing with cygutils</title>
|
2003-07-31 23:06:55 +02:00
|
|
|
<para>
|
|
|
|
There are several options for printing from Cygwin, including the
|
2004-01-11 09:32:09 +01:00
|
|
|
<command>lpr</command> found in <systemitem>cygutils</systemitem> (not to be confused with the
|
|
|
|
native Windows <command>lpr.exe</command>). The easiest way to use <systemitem>cygutils</systemitem>'
|
2003-07-31 23:06:55 +02:00
|
|
|
<command>lpr</command> is to specify a default device name in the
|
2004-12-24 22:58:38 +01:00
|
|
|
<envar>PRINTER</envar> environment variable. You may also specify a device
|
2003-07-31 23:06:55 +02:00
|
|
|
on the command line with the <literal>-d</literal> or <literal>-P</literal>
|
|
|
|
options, which will override the environment variable setting.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
A device name
|
|
|
|
may be a UNC path (<literal>\\server_name\printer_name</literal>), a reserved
|
|
|
|
DOS device name (<literal>prn</literal>, <literal>lpt1</literal>), or a
|
|
|
|
local port name that is mapped to a printer share. Note that forward slashes
|
|
|
|
may be used in a UNC path (<literal>//server_name/printer_name</literal>),
|
|
|
|
which is helpful when using <command>lpr</command> from a shell that uses
|
|
|
|
the backslash as an escape character.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
<command>lpr</command> sends raw data to the printer; no formatting is done.
|
|
|
|
Many, but not all, printers accept plain text as input. If your printer
|
|
|
|
supports PostScript, packages such as
|
2004-01-11 09:32:09 +01:00
|
|
|
<systemitem>a2ps</systemitem> and <systemitem>enscript</systemitem> can prepare
|
|
|
|
text files for printing. The <systemitem>ghostscript</systemitem> package also
|
|
|
|
provides some translation
|
2003-07-31 23:06:55 +02:00
|
|
|
from PostScript to various native printer languages. Additionally, a native
|
|
|
|
Windows application for printing PostScript, <command>gsprint</command>, is
|
2004-12-24 22:58:38 +01:00
|
|
|
available from the <ulink url="http://www.cs.wisc.edu/~ghost/">Ghostscript
|
2003-07-31 23:06:55 +02:00
|
|
|
website</ulink>.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
</sect2>
|
|
|
|
|
|
|
|
</sect1>
|