If you intend to use a character that is normally interpreted as
a command operator as a regular character, you must escape it
by preceding it with the ^
character.
Some command operators are valid at the OS/2 command prompt only, not
in DOS sessions.
The following lists the command operators in the order in which the command processors recognize them:
^
character escapes a command operator to be
recognized as regular input or output characters
(OS/2 sessions only).
For example, to display the following output on the screen:
TYPE YOUR AGE & SOCIAL SECURITY NUMBER ==>type:
ECHO TYPE YOUR AGE ^& SOCIAL SECURITY NUMBER ==^>
()
group commands so that they override
the regular order of precedence recognized by the command processor
(OS/2 sessions only).
>
redirects output to a file or device. If the file
exists, it is overwritten.
>>
redirects output to a file and appends to
it, if it exists.
<
retrieves and redirects input from the standard
input device.
The input source and the output targets of a program are predefined and identified by a number (called a handle). The following three exist:
STDIN
, whose handle is 0.
By default, this is the keyboard.
STDOUT
, whose handle is 1.
By default, this is the screen.
STDERR
),
whose handle is 2. By default this is the screen also, but this allows
for redirecting error messages separately.
STDIN
and writing to STDOUT
,
including STDERR
. If the
program does not implement these standard conventions, for example if
it is not a text-mode program or directly reads from and writes to the
hardware, redirection does not work.
If more than one operation is specified, only the last one is recognized.
Example 1: To redirect the output of the
DIR
command to the printer,
type:
DIR > PRNExample 2: To redirect the output of the
DIR
command
to a new file called listing.txt
, type:
DIR > listing.txtThe file
listing.txt
will be created automatically or
overwritten, if it exists already.
Example 3: To redirect both STDERR
and
STDOUT
, you redirect STDOUT
first and
then redirect STDERR
to STDOUT
. Redirection handles
used in place of file names must be preceded by an &
character. So to send all output and error listings from the DIR
command to a new file named listing.txt
, type:
DIR *.* >listing.txt 2>&1
|
), ASCII character 124,
is used for separating two commands for piping. A pipe intercepts
the output of one running program and sends it as input to another running program.
Pipes are most frequently used with filters. Filters are system
utilities that intercept data from STDIN
,
process it, and send it to STDOUT
.
&os2; provides three filters:
SORT
,
FIND
, and
MORE
. Many additional filters
are available from third parties.
Example: To display the current directory list sorted and send the output to a file named sorted.txt, type:
DIR | SORT > sorted.txtNote: When there is an invalid command on the left side of the pipe, the command on the right side of the pipe will not take effect. For example:
xxxx 2>&1 | MOREwill not pipe the error output to
MORE
because xxxx
is an invalid program.
&&
conditionally processes a sequence of
commands. A command in the sequence can be processed only if the preceding
command runs successfully
(OS/2 sessions only).
||
conditionally processes a sequence of commands.
A command in the sequence can be processed only if the preceding command
fails to run successfully
(OS/2 sessions only).
&
unconditionally processes individual commands in
a sequence, regardless of the success or failure of preceding commands in
the sequence
(OS/2 sessions only).