Running UNIX Applications on DOSWindows Machines


Running UNIX Applications on DOS/Windows Machines

Just as Windows users want to feel comfortable by using Windows applications when working in the UNIX environment, UNIX users may want to be able to use familiar UNIX commands when working in a Windows environment. You can do this in a few ways. One way is use a windowing environment, such as the X Window environment, on a Windows PC. Another is to use packages that allow you to issue UNIX commands on a Windows machine. Yet another is to use tools that have been developed on UNIX for Windows environments. Finally you can run a UNIX shell environment instead of the default command.com shell environment on a Windows PC.

Running an X Window System Server on Your Windows PC

If you are a UNIX user, you may want to perform UNIX tasks from a Windows PC in a familiar environment, such as the X Window environment. You can run an X Window System server on your Windows PC that allows you to interoperate between your Windows PC and a UNIX host machine. One of the ways you can do this is to use Cygwin/X. Cygwin/X is a port of the X Window System to Microsoft Windows by the Cygwin Project (http://www.cygwin.com/). Cygwin/X consists of an X Server, X libraries, and almost all the standard X clients, such as xterm, xhost, xdpyinfo, xclock, and xeyes. It works with Windows 95, 98, ME, NT 4, 2000, and XP. You can find information about it, and get the installation software, by going to either http://www.x.cygwin.com/ or http://www.cygwin.com/.

You can find out more about running X servers on your PC by accessing the USENET and consulting the newsgroup comp.windows.x.

Using Tools to Emulate a UNIX Environment

Several programs and collections of programs let you create a UNIX System-style environment on a Windows system, as well as emulate some Windows functions on a UNIX machine. In addition to programs that emulate actual UNIX commands, there are shells that implement the Korn shell or the C shell; and other applications are available for Windows. These programs can be very helpful in bridging the gap between the two systems, because they allow you to run UNIX-like commands on your system without giving up any of the DOS/Windows applications that you already have.

If you are a Windows system user, you have several possible reasons for using “lookalike” programs that emulate basic UNIX System commands. Utilities such as awk and vi enhance your Windows environment, providing capabilities missing from DOS under Windows, as well as useful capabilities for editing, formatting, managing files, and programming. If you are a Windows user who is just learning to use the UNIX System, adding UNIX System commands to your Windows environment is a good way to develop skill and familiarity with them without leaving your accustomed system. If you move between the two systems-for example, using the UNIX System at work and a Windows PC at home-creating a UNIX System-like environment on your Windows PC can save you from the confusion and frustration of using different command sets for similar functions. If you are a UNIX user and need to access Windows resources, there are also utilities for that; the next section discusses these.

The MKS Toolkit

As operating systems, the UNIX System and Windows are similar in some ways. The UNIX System and Windows both support multiple users and multitasking. Therefore, it is possible to create a good approximation to the working environment created by the shell and the common UNIX System tools on a Windows platform. A number of software packages exist that help you do this, including the MKS Toolkit from MKS, Inc. (formerly Mortice Kern Systems at http://www.mks.com/ or mkssoftware.com/). This product has grown significantly since its initial release to include new tools and APIs, but one of the original uses that is still relevant is that it provides an implementation of the shell and basic tools that you can use on your Windows computer. Inevitably, some look-alike commands work slightly differently from the UNIX System originals, because of fundamental differences between the two operating systems. Nevertheless, you will find the look-alike tools a useful bridge between the two operating systems, and a good way to ease gently into using a UNIX System.

This discussion will concentrate on some of the more useful commands included in the MKS Toolkit. The MKS Toolkit contains a collection of more than 100 commands-that correspond to most of the common UNIX System commands, including vi, awk, and the Korn shell, as well as commands such as strings and help-that you can run on a Windows computer.

In some cases, the UNIX System tools provide an alternative to a similar DOS command. For example, cp can copy several files at once, and rm can remove several files at once. In addition, the MKS Toolkit offers commands that do not have a DOS equivalent, such as file, strings, and head. Many DOS files are in the form of binary data; the Toolkit offers file to identify them, and od and strings to examine them. Many tools such as head, diff, and grep are useful for dealing with ASCII text files.

You run the MKS Toolkit commands as you would any other DOS commands. You simply type the command name with any options or filenames that it requires. For example, to view the contents of the current directory using ls, you type the command name:

 C:\> ls

The MKS Toolkit includes a help command that is particularly useful when learning to use UNIX System commands on Windows. It displays the list of options that go with each command. To use this, type help followed by the name of the command, as shown here:

 C:\> help ls

Experienced Windows users should refer to the chart of differences in commands between UNIX and DOS earlier in this chapter. It is easy to start out with commands like ls, pwd, or help. Next you might try file, strings, head, or od to give yourself an idea of the range of the UNIX System tools provided by MKS. You should now begin to recognize the power and flexibility that UNIX-style tools add to your Windows environment.

Other UNIX Toolkits and Applications for Windows

In addition to MKS, Inc., SourceForge provides a large number (over 100) of common GNU utilities that have been ported from UNIX to the native Win32 platform. These utilities depend on the existence of the Microsoft C-runtime routine msvcrt.dll but do not require the emulation layer provided by Cygwin/X. You can download these utilities from the Source Forge web page at http://unxutils.sourceforge.net/.

Running the Shell as a Program Under COMMAND.COM

Although you can run look-alike tools directly under the standard DOS/Windows command interpreter, COMMAND.COM, running a version of the UNIX shell on Windows can be very useful. Compared to COMMAND.COM, the UNIX shell is much more powerful and flexible, both as a command interpreter and as a programming language for writing scripts. Using the shell in place of or in addition to COMMAND.COM provides a more complete UNIX-style environment, including such valuable shell features as command-line editing and shell programming constructs. Furthermore, using the shell enables you to make use of some features of the look-alike tools that may not run properly under COMMAND.COM. One example is the capability to use commands that span more than one line, as in awk and sed commands. The UNIX System look-alike tools include versions of the shell. The MKS Toolkit includes the Korn shell.

The easiest way to run the shell on your DOS/Windows system is as a program running under COMMAND.COM-that is, you continue to use COMMAND.COM as your normal command interpreter, and when you want to use the shell, you invoke it as you would any other command.

To run the shell using the MKS Toolkit, type the following at the DOS prompt:

  C:\> Sh $

You will see the UNIX System prompt, which is by default a dollar sign. You then enter commands, with their options and filenames, just as you would in a UNIX System environment. For example, using sh rather than COMMAND.COM you can enter multiline arguments on the command line, which you need for awk and other commands. To exit the shell and return to COMMAND.COM, type exit.

This way of running the shell does not replace COMMAND.COM; it simply uses COMMAND.COM to run sh, which then acts as your command interpreter. This has the advantage of providing the most completely consistent DOS environment, for example, when a program requires you to use the DOS-style indicator for command options (slash), rather than the minus sign used on the UNIX System and by the shell. If you run the shell under COMMAND.COM, you can simply exit from the shell in order to run these particular programs.

If you want to execute the DOS equivalent of a .profile (similar to the environment set up in your AUTOEXEC.BAT) when you start the shell, you can invoke it with the L option:

 C:\> Sh −L $

This will set up any environmental variables you choose to specify in your profile.ksh file.

Replacing Command.Com with the Shell

If you want to emulate a UNIX System environment as fully as possible, replace COMMAND .COM with the shell as your default command interpreter. With this approach you do not use COMMAND.COM at all. This has the advantage of being most like a UNIX System environment. It even allows you to set up multiple user logins. It does not allow simultaneous use by more than one user, but it does permit each user to run under a customized environment-for example, with a different prompt or PATH. The disadvantage of this method is that you can no longer easily exit to COMMAND.COM, because it is not set up as your underlying shell. If you want to run a DOS program that demands the slash as a marker for command switches instead of the backslash, you may have to write a shell script to switch back and forth for this application. As another example, you may lose access to certain DOS commands that are built into COMMAND.COM rather than provided as separate programs.

Some frequently used DOS commands, such as DIR and TYPE, are internal, which means that instead of being separate executable commands, they are part of COMMAND.COM. If you are using the shell, it cannot call them directly In order to use these commands, you must set up an alias for them using the alias command.

If you use the shell as your command interpreter, put a command in your CONFIG.SYS file to tell the system to bypass COMMAND.COM and go directly to the shell or to an initialization program that allows multiple user logins. If you choose the initialization program, the system will set up multiple user logins, each one with its own environment. The documentation for the specific toolkit products such as MKS Toolkit will help you choose and set up the various possible configurations.

Setting Up the Environment for Utilities on DOS

Whether you replace COMMAND.COM with the shell or whether you run the shell as a program under COMMAND.COM, you must set up the proper working environment. The choice between these alternatives will determine how you set up the MKS system on your computer. Setting up the environment is tricky because MKS needs some of the environment of both operating systems. It needs to have certain DOS environmental variables set properly, and it sets up a profile.ksh file to correspond to a UNIX System .profile file. You need AUTOEXEC.BAT to set variables like PATH, ROOTDIR, and TMPDIR, which MKS requires in order to run properly If you run under COMMAND.COM, the system will start with AUTOEXEC.BAT to set the other environmental variables. The AUTOEXEC. BAT file can also include the SWITCH command to allow you to specify command options with a minus sign and to use slash as the separator in directory pathnames.

UNIX Kernel Built-in Capabilities

In addition to third-party software tools that let you emulate DOS or UNIX environments, the UNIX kernel itself can be used for simultaneous access to both DOS and UNIX. Although you cannot run DOS executables without some type of software emulation, you can mount DOS file systems directly from the kernel and access DOS devices directly You can then manipulate the contents of the devices directly For example, you can copy move, and delete data on DOS devices directly from the kernel.




UNIX. The Complete Reference
UNIX: The Complete Reference, Second Edition (Complete Reference Series)
ISBN: 0072263369
EAN: 2147483647
Year: 2006
Pages: 316

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net