Win4Lin User's Guide |
Chapter 7 -- Mixing Windows and Linux |
(User's Guide Table of Contents) | (Chapter Table of Contents) |
Previous Chapter - Using Win4Lin from the command line | Next - Appendix A - Using remote X terminals |
For example, you can pass Linux environment variables to Win4Lin sessions.
You can also convert text files from
DOS to Linux format and vice versa.
Working with text files
DOS and Linux also store text files in different formats. The Linux system stores text lines as a sequence of characters terminated by a line-feed character. DOS (and Windows), 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 or Windows on your Win4Lin system, you can use any text file that was created with DOS or Windows, because these files are stored in DOS format even when they are created on the shared Linux filesystem.
To use a text file in Linux format with DOS programs, you
must convert
the file to DOS text format.
This can be done using the Win4Lin command
"unix2dos".
For example:
unix2dos letter ltr.dos
creates a copy of the Linux text file "letter" in the new file "ltr.dos"
in DOS text format.
In the same way you can convert from DOS text Linux text format using
the Win4Lin command
"dos2unix".
For example, the command
dos2unix ltr.dos letter
creates a copy of the DOS text file "ltr.dos" in the new file "letter"
in Linux text format.
You can use unix2dos and dos2unix both in the DOS and Linux environment because Win4Lin supplies both DOS and Linux versions of these utilities.
You can also combine these commands with other DOS or Linux
commands through pipes and redirection.
For example, the command
dos2unix names.txt | sort > newnames
Restrictions:
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)
Even when you do not know the format of a text file, you can safely 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 Linux environment variables to DOS/Windows
DOS (and hence Windows) and the Linux 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 Win4Lin environment exactly as you would use them on a conventional DOS and Windows computer.
In addition, you can set Linux environment variables so they are available to DOS and Windows programs run from the Linux shell. This is especially useful if you are mixing environments and, for example, using Linux scripts to gather information that you then pass to your DOS or Windows application.
Use the Linux DOSENV environment variable to specify any Linux environment variables you want to pass to DOS and Windows from the Linux shell, as follows:
DOSENV=
variable1,variable2,...
export
variable1 variable2... DOSENV
To accomplish these operations, you would type:
MONTH='June'
YEAR='1995'
DOSENV='MONTH,YEAR'
export MONTH YEAR DOSENV
Observe the following rules:
You can run any DOS program from the Linux command line as follows:
dos program &
In the same way you can run Windows programs:
win program &
For example, you can use the following command to start up the Windows WordPad editor to edit a file.
win wordpad c:file.doc &
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, Win4Lin 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 Linux 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 Linux 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:
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.
Translating DOS switch characters and path separators
By default, Win4Lin
requires Linux-style switch
characters and path separators when you issue DOS
commands from the Linux shell.
For example:
dos +b dir /docs -w
Before passing the command to DOS, Win4Lin
automatically translates this command to:
dir \docs /w
Use the -t option to prevent Win4Lin 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 Linux shell from interpreting metacharacters in a DOS command.
Running Linux programs from DOS
The Win4Lin
on unix utility allows you to run Linux 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 Linux programs and control their
execution and output from the DOS environment.
Restrictions:
on unix pr -o10 -w65 -l54 -d /tmp/longfilename1
Specify Linux filenames with their full Linux names, not with their mapped names.
The "on unix" command runs the specified Linux process in the current directory of your current drive, provided the drive accesses the shared Linux file system. If your current drive is not a shared file system drive, the "on unix" command fails and displays an error message.
To execute multiple Linux commands with a single
"on unix" command, separate the Linux commands with
semicolons and surround them with parentheses. For
example:
on unix (ls ; cat names)
The "on unix" command automatically converts the text output of the Linux command from Linux format to DOS format. That is, the Win4Lin unix2dos utility is built in.
If the "on unix" command cannot execute the requested Linux 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 unix" command attempted to run.
Using Linux command names directly
When you want to avoid typing
"on unix
", copy or link the on.exe
program to the names of the Linux
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 Linux 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:\Win4Lin\on.exe getname.exe
Then, type the following from the DOS prompt:
getname joe
Alternatively, you can use the
Linux "ln" 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 Linux prompt, type:
ln -s /var/win4lin/dosroot/merge/on.exe getname.exe
You enter all options and arguments following the renamed copy of the on.exe command exactly as you would enter them at the Linux prompt.
Observe the following precautions and restrictions:
on unix
". For example:
on unix mycalendar on unix type myfile
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 unix" command, the Linux system must be able to find the Linux command named in the "on unix" command line; that is, the Linux command must be in your Linux search path.
Win4Lin executes Linux commands that you run with the "on unix" command under the standard Bourne shell, sh. Any Linux environment variables exported by the shell that started your DOS environment are available to Linux programs executed with the "on unix" command.