home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Simtel MSDOS 1992 September
/
Simtel20_Sept92.cdr
/
msdos
/
batutl
/
batutl2.arc
/
SEND.DOC
< prev
next >
Wrap
Text File
|
1986-08-15
|
27KB
|
469 lines
¢4 L SEND.COM 1.6
INTRODUCTION
SEND.COM is an enhanced version of the ECHO command, ideal
for sending escape sequences to the printer or screen. The
documentation is primarily a tutorial on ECHO, SEND and redirection
of output. If you already feel expert on ECHO and redirection, you
can skip to the final SUMMARY section to get a short manual on
SEND.
SEND, its source code, documentation, and demonstration files
are copyright 1985 by Howard Rumsey and Barry Simon. They are
placed in public domain with one restriction and may be used for any
purpose including commercial use. It is recomended that the the
full set of files be distributed together. The sole restriction
is that the two files with copyright notices must be distributed
with these copyright notices.
Version 1.5 differs from the unnumbered version 1.0 by
including discussion of redirection of send through COMMAND.COM and
additional $<Cap Letters> commands.
SEND.COM was written by Howard Rumsey. The source file is
found on the disk together with several demonstration files:
MONODEMO.BAT
COLORDEM.BAT
KEYRD.BAT
KEYOFF.BAT
PRINTDEM.BAT
The first four require you to have installed ANSI.SYS via your
CONFIG.SYS file. The first two illustrate the use of SEND with
monochrome and color monitors respectively. Keyrd will redefine
your F9 key to mean "dir" followed by <Enter> and F10 to mean "cls"
followed by <Enter>. Keyoff returns the keys to their original
meaning. The final batch file will illustrate the use of SEND if
you have an IBM graphics or compatible printer attached to LPT1.
This batch file can be run on either monitor, but if you have a
color monitor, you should run it with that as tne active monitor.
The demonstration files and this documentation were written by
Barry Simon.
The following files are also included:
BOLDPRN.BAT: Uses SEND to printout a file of your choice in
boldprint on an IBM printer. Type in the command
"boldprn 'filename'"
TRIAL.TXT: Used in printdem to illustrate boldprn.bat
ANSISYS.ART: An article by B. Simon, which first appeared in
the CAPITOL PC Monitor which describes the use of
ANSI.SYS.
The batch files have numerous remarks embedded in them and you
should copy them to your printer. You should note that you
couldn't do that if these batch files had used ECHO and embedded
escape characters rather than SEND!
These programs are hereby placed in the public domain.
Comments on this program can be sent to:
Barry Simon Howard Rumsey
Caltech 253-37 or Caltech 158-79
Pasadena, CA 91125 Pasadena, CA 91125
CompuServe 72426,3722
This documentation can be printed out by turning on your
printer, making sure that the paper is properly aligned and typing
"copy send.doc prn" at a DOS prompt. If you have an IBM graphics
printer, you can get an even nicer copy by typing "boldprn send.doc"
at the DOS prompt.
INSTALLING SEND.COM
Some effort has been expended to keep SEND.COM under 512
bytes so it takes up only one sector if you have a floppy based
system. In that case, you need to copy SEND.COM to your utility
disk. SEND is not resident so the disk needs to be present
whenever SEND is invoked. On a hard disk system copy SEND.COM to a
directory which is one of your DOS path search directories set by
the PATH command.
USING ECHO
You may be used to exploiting ECHO in your batch files but
may not be aware that it can be invoked from the DOS command line.
If that is the case, type in at the DOS prompt:
echo hello
You need to also hit <Enter> but I won't keep saying that. The
response is amusing but not useful. Next try:
echo hello > prn
SEND page 2
More interesting! Still not so useful but at least if you ever
want to use your printer as a typewriter (why anyone would want to
do this in preference to using a real word processor is beyond me!)
you can do it yourself without needing a BASIC program which does
precisely that.
Now try
echo <Ctrl G>
where "<Ctrl G>" means to hit a "control-G", that is to depress the
<Ctrl> key and strike the G and try
echo <Ctrl G> > prn
These are decidedly more interesting and you may even think of some
uses for them in batch files!
Next try turning off your printer, carefully aligning your
printer paper, turning your printer back on and typing
echo <Ctrl L> > prn
<Ctrl L> is the command to send a "top of form" to your printer but
if you look carefully you will discover that more than a top of
form was sent to the printer. ECHO automatically inserts a
carriage return-line feed pair (CR-LF) to the end of any line so
your last command first sent a top of form but then advanced the
paper one additional line. Annoying, isn't it?
Next try:
echo <Esc>
and
echo <Ctrl [>
(Escape and Control-[ are the same). This doesn't do what you
might hope. <Esc> is interpreted by DOS as a desire on your part
to abort the present command and thus you cannot use ECHO at the
command line to send an <Esc> to either the screen or your printer.
This is unfortunate since ANSI.SYS allows you to do all
sorts of nice things if you send the proper "escape sequences" to
the screen and many printers can be told to turn on boldface or
other neat things by sending escape sequences to them. You can
send such sequences to the printer by using some word processors
(even EDLIN (ugh!) if you use its <Ctrl V> feature) to make a file
with embedded escape characters which you can copy to your printer.
But you then need to have these files around and you have files
with embedded control characters which you may have trouble
printing out or sending over a modem.
SEND is intended to remedy these defects of ECHO:
1. It does not terminate line in a CR-LF combination; one can
add such a pair "by hand".
2. Typing "send ^G" is equivalent (except for the lack of a
CR-LF) to typing "echo <Ctrl G>" so one need not fill files
with control characters.
3. Typing "send ^[E > prn" will send a <Esc>E to the printer
thereby turning on "emphasized" print.
In addition, as will be explained, SEND supports the PROMPT $-
characters.
SEND: CONTROL CHARACTERS
SEND works much like ECHO but if the string to be echoed
includes the caret (<Shift 6> which appears as ^), different rules
apply. SEND will replace ^a by the character <Ctrl A> (ASCII 1),
etc. ^ followed by any letter is replaced by the corresponding
control character whether the letter is upper case or lower case.
The remaining control characters:
^@=ASCII 0
^[=ASCII 27 (1B Hex)=<Esc>
^\=ASCII 28 (1C Hex)
^]=ASCII 29 (1D Hex)
^^=ASCII 30 (1E Hex)
^_=ASCII 31 (1F Hex)
may be included by following a caret by the appropriate symbol.
Obviously, ^[, the escape character will be used most often. If ^
is followed by any other ASCII code such as ^2 or ^? or ^*, a
control character is also sent but the exact rules needn't concern
us.
If you wish to "send" a caret the string "$^" will have the
dollar sign striped away and a caret will be sent. Thus the
command "send ^^a" will send the two characters <Ctrl ^> (ASCII 30)
followed by a (ASCII 97) while the command "send $^^a" will send
the two characters caret (ASCII 94) followed by <Ctrl A> (ASCII 1).
SEND does not automatically terminate any line in a CR-LF
(ASCII 13,ASCII 10) pair. Thus typing "echo hello" at the DOS
command line will result in two lines on the screen before the
next DOS prompt: one line saying hello and the other a blank line.
SEND page 3
Typing "send hello" will only produce the one line saying hello.
If one wants the CR-LF pair, one can insert it "by hand"; thus
"send hello^M^J" will have the exact same effect as "echo hello".
As we will see in the next section "send hello$_" is also
equivalent. It is important to remember to put in these CR-LF by
hand if you are using SEND in a batch file to echo a message to the
screen. For example the four line batch file
echo off
cls
send hello
send there
will produce the string "hellothere" on one line on the screen
while adding $_ after "hello" or even replacing the last two lines
by
send hello$_there
will produce a two line message with one word on each line.
SEND: $ LOWER CASE CHARACTERS
SEND supports the $-meta string conventions of the DOS PROMPT
command with one important changes (see $h below). Specifically,
if a $ appears in a string following a SEND command (EXCEPTION: if
the $ is immediately preceded by a caret ^$ is interpreted as <Ctrl
D> unless of course its preceded by two carets...), a special
interpretation is made if the $ is immediately followed by one of
the following:
$,^
g,l,b,q
h,_,e
t,d,p,v,n
P,M,D,Y,T as descibed in the next section
In all other cases, the $ is ignored so that "send $a" will send
only "a" to the screen. "$$" and "$^" follow the same rule of
stripping away the $ except that the $ and ^ are sent in their
conventional meaning rather than as special symbols for SEND.
The case of the letter following $ is significant. $G will be
interpreted as G while $g as >.
$g,$l,$b,$q correspond to the characters >,<,|,=
respectively. You can use the ordinary "=" in a line starting with
"send", but you CANNOT type >,< or | in such a line since DOS will
interpret these symbols as redirection or piping. You must use
the $-meta string instead. For example, if you use FANSI-CONSOLE
and want to send the ANSI code "<esc>[>4h" typing the command "send
^[[>4h" will make a file "4h" with two bytes in it while "send
^[[$g4h" will do exactly what you want.
$h is equivalent to ^H, ASCII 8, the "backspace" which, if
sent to the screen, moves the cursor back one space. Unlike the
PROMPT $h, the SEND $h does not erase the previous character. Thus
"send a$h" will show an "a" on the screen and "send a$hb" will show
a "b" on the screen since the cursor will backspace one unit and
the b will overwrite the a. But the command "send a$hb>file" will
produce a file with three bytes: a,<Ctrl H>,b.
$_ is equivalent to ^M^J, i.e. to a CR-LF pair.
$e is equivalent to ^[, the escape character (ASCII 27).
$t and $d send the time and date in the form returned by the
TIME and DATE commands. Thus the time will appear as HH:MM:SS:hh.
If you only want the hours and minutes to appear on the screen, you
can type "send $t$h$h$h$h$h$h ". (There are six spaces after
the final $h and they are important!).
$p will send the current full pathname including the current
drive such as "C:\bin\batfiles" or "C:\".
$v returns the current DOS version and $n the current default
drive letter without a trailing colon.
SEND: $ UPPER CASE CHARATERS
Send also supports a small number of extensions of the propmt
meta strings:
$P: For any directory but the root directory $P will send
$p\; for the root directory, $P sends just \. Thus if a file has
name as its filespec, "send $Pname" will always return the full
path-and-filespec while "send $p\name" will only work correctly if
you're not in the root directory.
$T: returns the time in HHMM form so if its 9:15:37:45 AM, it
will return 0915 and if its the same time PM, it will return 2115.
$M: returns the month in MM form so January is 01 and
December is 12.
$D: returns the day in DD form so on the first, you'll get 01
and on the twentieth 20.
$Y: returns the last two digits of the current year.
SEND page 4
These last four metastrings are especially useful in
connection with redirection through command.com as discussed below.
SEND AND ANSI.SYS
One of the most useful things you can do with SEND is exploit
the ANSI.SYS device driver. ANSI.SYS is a file that comes with DOS
(version 2.0 and higher). You need to load it in your CONFIG.SYS
file. If you already have such a file, add a line
device=ansi.sys
to it and place ANSI.SYS in your root directory or, even better,
place ANSI.SYS in a directory, say GEORGE and add a line
device=\george\ansi.sys
to your CONFIG.SYS file. If you don't have such a file, add one to
your root directory with one of the above lines and while you're at
it, you should probably add files=20 and buffers=15 (unless the
memory of your computer is very limited).
You can read about the syntax of the ANSI.SYS commands in the
DOS 2.0 manual or the DOS 3.0 technical reference. ANSI.SYS can be
used to control screen colors on a color monitor, and attributes on
a monochrome monitor. For example,
send $e[1;31;42m
will produce an unpleasant screen while
send $e[1;33;44m
will be more to your liking. Actually, it is best to set your
screen colors using the DOS PROMPT command. You can use SEND to
call up colors and attributes for effect in batch files. The two
batch files MONODEMO and COLORDEM provided illustrate this.
You can also use SEND and ANSI.SYS to redefine keys in DOS.
This is illustrated by KEYRD. Try the F9 and F10 keys after
running KEYRD and turn off these special meanings by running
KEYOFF.
An article which originally appeared in the CAPITOL PC
Monitor is included on the disk if you want to know more about how
to use ANSI.SYS.
REDIRECTION OF OUTPUT
DOS, following UNIX, supports two virtual devices called
"standard input" (stdin) and "standard output" (stdout). Programs
rather than sending their output to a specific device like the
screen or printer can send them to stdout and similarly rather than
take input from a specific device, they can take it from stdin. If
not specified otherwise, stdout is sent to the currently active
screen and stdout is taken from the keyboard (i.e. the DOS command
line). However, one can redirect stdout to another device. For
this to work the program MUST send its output to stdout. For
example, the "main output" of the COPY command goes not to stdout
but to the second file specified on the command line; only the
message that COPY sends goes to stdout. Thus "copy send.doc prn"
will print this file on your printer, but "copy send.doc > prn" will
print the error message
File cannot be copied onto itself
0 File(s) copied
If a program takes its input from stdin, that too can be
redirected. One redirects output using the symbol ">" and input
using "<".
SEND sends its output to stdout and that can be redirected,
for example to a printer or file. It takes its input from the
keyboard rather than from stdin so one cannot redirect input.
SENDING PRINTER CONTROLS
SEND can also be used for sending control sequences to your
printer. Unfortunately, the sequences to be used tend to be highly
dependent on the brand and/or model of your printer. The PRINTDEM
batch file included and the examples presented here work for the
IBM graphics printer and compatibles. You may need to figure out
how to modify things to handle your own printer. The simplest
example is a one line batch file entitled tf.bat
send ^L> prn
Typing tf at the DOS command line will cause your printer to eject
a page. You might even want to define a function key to mean tf.
A more sophisticated example is the five line batch file
BOLDPRN.BAT, provided as a sample file:
echo off
cls
send $eE$eG>prn
copy %1 prn
send $eF$eH>prn
SEND page 5
Thus typing "boldprn MYFILE" will print a boldface (=emphasized and
doublestrike) copy of myfile on your printer. You might consider
adding the line:
send $P%1 printed on $d>prn
before the "copy..." line.
Other examples can be found in the PRINTDEM batch file.
A particularly useful way of sending printer codes is to use
send in CED synonyms if you have the program CED.
ECHO, SEND AND PARAMETERS
If you have a batch file called foo.bat and type the command
foo hello
at the DOS command line, hello is treated by DOS as the first
parameter, denoted %1. Thus the line "echo %1 there" in the batch
file will type the phrase "hello there" on the screen. Since this
is a DOS service, "send %1 there" will work the same way. DOS
makes the replacement before the line in the batch file is
processed.
USING BOTH ECHO AND SEND
There is no reason not to use both ECHO and SEND on different
lines of batch files. In the demonstration files we only used SEND,
but if one doesn't need the special features of SEND, it is more
convenient to use ECHO and not have to worry about inserting the
CR-LF pairs by hand.
REDIRECTING SEND THROUGH COMMAND.COM
If you use SEND for a while, you will wish you could send its
output to the command line rather than just to the screen. That is
typing "send ren myfile file$M$D" on December 15, will echo "ren
myfile fill1215" on the screen but will not issue that command to
DOS. One can use DOS's pipe facility to issue such commands to DOS
but some care is needed. If not done exactly right, your system
will hang although the only effect will be the need to reboot.
One can make a new "shell" of DOS by issuing the command
"command" if the DOS file COMMAND.COM is in the current directory
or in your DOS search path. This new shell remains resident until
the command "exit" is issued.
To explain the care needed consider some examples. Unless
you like rebooting, don't actually try these examples out! If you
type "send cls|command" at the DOS command line, the letters "cls"
will appear on your screen after the copyright for the appropriate
version of DOS. However, when you try to push the <Enter> key
nothing will happen. You told the new command.com to take its
input from the output of SEND and it stubbornly won't take any from
you; the only keystroke to which it will respond is the one
requiring three fingers! So you might try, "send cls$_|command".
This will work in the sense that your screen will clear but after
that, the system will hang. The correct thing to do is "send
cls$_exit$_|command". This will clear the screen and unload the
new shell of command.com returning control to you. So the moral is
whenever piping send's output through COMMAND.COM you should be
sure that the end of the string in "send 'string'|command" is
"$_exit$_"
Of course, you'd never use this redirection to clear the
screen. Here are two possible uses. You might make a batch file
called return.bat with the single line:
send %1 %2$_$n:$_cd $p$_exit$_|command
Thus, if you have a batch file lotus.bat which switches to the
directory with 123 and runs it, typing "return lotus" will run
lotus.bat and then return you to the drive and directory that you
started on. You needn't worry that having told COMMAND.COM to only
accept input from the output of SEND, your keyboard will be locked
up when you try to communicate with 123. COMMAND.COM will not
accept input from the keyboard, but it has loaded 123 which is
configured to take input from the keyboard. However, if you run a
program with return.bat that tries to issue commands to DOS, it may
not work. Mind you, there will be no problem with the program
using DOS services as it might in saving a file.
Here is another use. Suppose that your communication program
captures input into a file named "temp" by default. You want to
make a batch file which collects your electronic mail and stores it
in a file whose name is stamped with today's date. Include the
line
send ren temp mail$M$D.$Y $_exit$_|command
in the file and things will work exactly as you wish.
SEND page 6
In this last example, it is important to mention that when
you exit an extra shell of DOS, it returns control to the calling
program, even if the calling program is a batch file. Thus the
above line will work fine even in the middle of a batch file.
Two warnigs: NEVER load a program that becomes permanently
resident in the string you send to COMMAND.COM. You will then be
unable to exit the new DOS shell and your system will hang. Do not
try to change environmental variables (path, prompt, etc.) with the
command string. Nothing bad will happen but the change will only
take effect in the new shell and when it is exited, the changes
will be lost.
SUMMARY
SEND works just like the ECHO command in DOS (including the
fact that its output but not its input can be redirected) except:
1. CR-LF pairs are not automatically inserted at the end of
each line but must be inserted (either as $_ or as ^M^J) at any
desired point.
2. ^ and $ are not interpreted in the usual way but have
special meanings; "$$" will be interpreted as "$" and "$^" as "^".
3. ^ followed by any letter (upper or lower case) or the
other appropriate symbols (@,[,\,^,_) are interpreted as the
corresponding control characters. In particular, ^[ will send an
<Esc> (ASCII 27). It is better not to follow ^ by any other symbol.
4. $ followed by ^,P,M,D,Y,T or any of the PROMPT meta
characters ($,t,d,p,v,n,g,l,b,q,h,e,_) has the meaning given in the
DOS manual description of the PROMPT. $^ gives a literal ^ and $P
means the same a $p in the root directory and the same as $p\ in
any other directory. $h does not have the PROMPT meaning of
backspace AND ERASE but only means backspace, i.e. <Ctrl H> (ASCII
8). In particular, $e will send an <Esc> (ASCII 27) and $_ a CR-
LF pair. $M,$D,$Y return two digits for the month, day and year.
$T returns the four digits HHMM in the time.
HISTORY
Version 1.0 10-15-85
Version 1.5 12-05-85
Added $M,D,Y,T commands and added to the documentation the
possibility of piping send throungh COMMAND.COM
Version 1.6 01-03-86
Modified send to work properly with XCED, a part of the PCED
package. Previously, send assumed it command input ended with a CR
which DOS automatically inserts at the end of command lines. Now
send ends its input when it reaches a NULL (ASCII 0) or the number
of characters specified by DOS for the input, whichever comes
first.
¢0 L