SCO Merge User's Guide
Chapter 7, Mixing DOS and UNIX

Chapter 7

Mixing DOS and UNIX


Table of Contents

This chapter describes some features SCO Merge makes available due to mixing of DOS and UNIX environments.

For example, you can pass UNIX environment variables to DOS and run UNIX programs from DOS. You can also convert text files from DOS to UNIX format and vice versa.

Working with DOS and UNIX files

DOS and UNIX use different filenaming conventions. See ``Accessing files with invalid DOS names'' for an explanation of the differences.

DOS and UNIX also store text files in different formats. The UNIX system stores text lines as a sequence of characters terminated by a line-feed character. DOS, in contrast, terminates text lines with a carriage-return character followed by a line-feed character. A file created in one format can appear corrupted when accessed by the other.

When you use DOS on your SCO Merge system, you can use any text file that was created with DOS, because these files are stored in DOS format even when they are created on the shared UNIX filesystem.

To use a text file in UNIX format with DOS programs, you must convert the file to DOS text format using either the SCO Merge unix2dos or the SCO UNIX xtod command. For example:

unix2dos letter ltr.dos

To convert a file and copy it from one drive to another in one step, use drive letters to qualify the filenames. For example:

unix2dos c:letter a:ltr.dos

You can convert text files created with DOS to UNIX text format with either the SCO Merge command dos2unix or the SCO UNIX command dtox. For example:

dos2unix ltr.dos letter

You can use unix2dos and dos2unix both in the DOS environment and from the UNIX shell. In the DOS environment, use DOS filenames, including mapped names when appropriate. From the UNIX shell, use UNIX (unmapped) filenames. For example:

unix2dos letter.tobob ltr.bob

You can combine these commands with other DOS or UNIX commands through pipes and redirection. For example:

dos2unix names | sort > newnames

Do not specify the same name for the source file and the target file or try to redirect your output back into the source file. The following examples are incorrect:

dos2unix names names (incorrect)
dos2unix names > names (incorrect)

When you do not know the format of a text file, use the unix2dos or dos2unix command to convert to the format you need, just to be sure. The commands do not change anything when the file is already in the target format.

Passing UNIX environment variables to DOS

DOS and the UNIX system use similar concepts of environment variables. An environment variable is a value (assigned by you, the operating system, or an application) that is available to all commands and applications that run in the same environment.

You can use DOS environment variables in the SCO Merge environment exactly as you would use them on a conventional DOS computer.

In addition, you can set UNIX environment variables so they are available to DOS programs run from the UNIX shell. This is especially useful if you are mixing environments and, for example, using UNIX scripts to gather information that you then pass to your DOS application.

Use the UNIX DOSENV environment variable to set any UNIX environment variables you want to pass to DOS from the UNIX shell, as follows:

  1. Set the required environment variables using standard UNIX syntax:

    variable1=value1
    variable2=value2

    .
    .
    .

  2. Set DOSENV to the names of all the environment variables that you want to pass to DOS. Use commas (but no spaces) to separate the variable names:

    DOSENV=variable1,variable2,...

  3. Export each of the defined environment variables and DOSENV:

    export variable1 variable2... DOSENV

Assume, for example, that you want to set values for environment variables MONTH and YEAR.

To accomplish these operations, you would type:

MONTH='June'
YEAR='1995'
DOSENV='MONTH,YEAR'
export MONTH YEAR DOSENV

Observe the following rules:

Running DOS programs from the UNIX command line

You can run any DOS program from the UNIX command line as follows:

dos program

For example, you can use the following command to copy file1.txt to file2.txt using the DOS copy command from the UNIX prompt:

dos copy file1.txt file2.txt

If the DOS program is stream-oriented (see ``Specifying DOS application output behavior''), you can even combine UNIX and DOS commands on the same line by using I/O redirection or pipe mechanisms.

Specifying DOS application output behavior

A DOS program that does all its input and output via standard I/O is called stream-oriented. Some standard DOS commands, such as dir, are stream-oriented programs. DOS applications that do not write directly to the system screen (many compilers, for example) are also stream-oriented programs.

A DOS program that avoids some or all of the standard I/O mechanisms is called display-oriented. DOS applications that write directly to the system video memory (including many text-processing, database, and spreadsheet programs, as well as most games) are display-oriented programs.

To properly handle I/O for a DOS program, SCO Merge must know whether it is stream-oriented or display-oriented. All DOS programs are assumed to be display-oriented unless you specify otherwise.

You can run any DOS program from the UNIX command line with the default assignment of display-oriented. To take advantage of the additional flexibility available with stream-oriented programs, though, you should identify these programs as such, using the +b option.

For example, the following command starts the application appl as a stream-oriented program:

dos +b appl

When you identify a stream-oriented DOS program with the +b option, you can use UNIX pipe and I/O redirection mechanisms to manipulate the program's input and output.

To determine whether a program is display-oriented or stream-oriented, use these guidelines:

If you are uncertain whether a noninteractive program is stream-oriented, you can perform the following test. Start the DOS environment and run the program in question, redirecting the input or output (as appropriate) to a file. For example, to test output redirection for the program appl, issue this command from the DOS prompt:

appl > temp

When the program has finished executing, display the contents of the file you created. You can do this with the DOS type command:

type temp

You can also use a text editor to display the contents of the temp file. If the output of your DOS program is correctly captured in this file, the program has stream-oriented output.

To find out whether appl accepts stream-oriented input, you can test it with a command such as:

appl < con

This command tests input redirection from the console. If appl behaves correctly, it accepts stream-oriented input.


NOTE: If you run a program that is actually display-oriented with the +b option, screen output is lost. To abort the program, send a UNIX interrupt (by default, the <Del> key).

Translating DOS switch characters and path separators

By default, SCO Merge requires UNIX-style switch characters and path separators when you issue DOS commands from the UNIX shell. For example:

dir +b dir /docs -w

Before passing the command to DOS, SCO Merge automatically translates this command to:

dir \docs /w

Use the -t option to prevent SCO Merge from translating switch characters and path separators on a DOS command line.

For example, consider a hypothetical DOS compute command, which does simple arithmetic calculations like division and subtraction. With the default translation in effect, a command such as:

dos +b compute 8 - 4

would be translated to:

compute 8 / 4

Obviously, this would not produce the result you had intended.

To prevent this translation, you could type:

dos +b -t compute 8 - 4

The -t option does not prevent the UNIX shell from interpreting metacharacters in a DOS command.

Running UNIX programs from DOS

The SCO Merge on utility allows you to run UNIX programs from the DOS environment and view the output as though the programs were actually running under DOS. You can also view status information concerning UNIX programs and control their execution and output from the DOS environment.

The on utility can only be used to execute noninteractive UNIX commands.


NOTE: This utility is not available when you are using Windows 95.

Specifying the UNIX command

UNIX commands can contain all options and arguments exactly as you would type them at a UNIX prompt. For example, from your DOS prompt:
    on unix pr -o10 -w65 -l54 -d /tmp/longfilename1

Specify UNIX filenames with their full UNIX names, not with their mapped names.

The on command runs the specified UNIX process in the current directory of your current drive, provided the drive accesses the shared UNIX file system. If your current drive is not a shared file system drive, the on command fails and displays an error message.

To execute multiple UNIX commands with a single on command, separate the UNIX commands with semicolons and surround them with parentheses. For example:

    on unix (ls ; cat names)

The on command automatically converts the text output of the UNIX command from UNIX format to DOS format. That is, the SCO Merge unix2dos utility is built in.

If the on command cannot execute the requested UNIX command, either because it cannot find a requested file or because you do not have execute permission for a requested file, it returns an error message indicating the name of the command that the on command attempted to run.

Using UNIX command names directly

When you want to avoid typing on unix, copy or link the on program to the names of the UNIX commands you want to run directly from the DOS prompt. Include the filename extension .exe in the renamed copy of on.exe.

Assume, for example, that you have a UNIX program called getname that displays a user's full name when given either a first or last name. To make getname executable under DOS, copy on.exe with the command:

    copy j:\merge\on.exe getname.exe

Then, type the following from the DOS prompt:

    getname joe

Alternatively, you can use the UNIX link ( ln(1) ) command to achieve the same result. The linking method saves disk space since it does not actually duplicate a copy of on.exe. For example, to link getname, from the UNIX prompt, type:

    ln -s /usr/merge/dosroot/merge/on.exe getname.exe

You enter all options and arguments following the renamed copy of the on command exactly as you would enter them at the UNIX prompt.

Observe the following precautions and restrictions:

Search path and other environment considerations

on.exe, any renamed copies of on.exe, and any commands linked to on.exe must be in your DOS search path.

In addition, with any form of the on command, the UNIX system must be able to find the UNIX command named in the on command line; that is, the UNIX command must be in your UNIX search path.

SCO Merge executes UNIX commands that you run with the on command under the standard Bourne shell, sh. Any UNIX environment variables exported by the shell that started your DOS environment are available to UNIX programs executed with the on command.


 –  –  –  –