home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Simtel MSDOS 1996 September
/
Simtel-MSDOS-Sep1996-CD2.iso
/
disc2
/
c
/
input.doc
< prev
next >
Wrap
Text File
|
1986-05-03
|
4KB
|
151 lines
4-May-86 13:51:39-PDT,3775;000000000001
Date: Sun, 4 May 86 15:49:25 cdt
From: Peter Wu <pwu@unix.macc.wisc.edu>
To: info-ibmpc-request@mosis
Subject: INPUT.C
INPUT - read a string from console in a batch file
SYNTAX
INPUT <prompt> <var name>
Where <prompt> is a "quoted" string and <var name> is the name of
an environment variable to accept the input string.
Use \" to include the double quote character itself in the
prompt.
BRIEF DESCRIPTION
Just like BASIC's INPUT statement, except this one works in
batch files, so you can read a string from the user and use the
string in your batch file.
E.g. For kicks, you can put this in your autoexec.bat:
echo off
INPUT "Password:" pwd
if %pwd%.==who. goto ok
echo Access denied
crash
:ok
echo. <- This prints an empty line
echo Permission Granted
The string enterd will always be converted to lower case before
it is stored in the environment variable.
If the enviroment variable you specified already exist, it's
contend will be replaced by the user's input.
Since this programs stores the string in an environment variable,
you might run out of environment space. Here's a way to expand
your environment space to 992 bytes:
shell=c:\command.com /p /e:62
Put the above line in your config.sys file. This is an
undocumented feature.
WARNING
This program relies on several undocumented features of DOS 3.1.
It has been tested on PC AT and PC XT only. For example, using
%pwd% to refer to the value of environment variable pwd might not
work in other DOS. The INPUT program itself relies on
undocumented memory allocation block structure used by DOS to
find DOS's environment space.
I resort to undocumented features only because it's almost
impossible to accomplish all these by using documented features
alone.
If you try it on a clone and/or try it with a different version
of DOS, let me know whether or not it works.
EXAMPLES
There's this game called HACK that requires a configuration file
to indicate many options, among which the drive name of your ram
disk if you have one. I installed this game on a PC Network where
some PC's have ram disk and some don't. So this is what I put in
the HACK start up batch file:
echo off
copy F:\games\hack\hack33.cnf hack33.cnf
INPUT "Drive name of your ram disk (if you have one)? " d
if %d%.==. goto noram
echo RAMDISK=%d% >> hack33.cnf
:noram
F:\games\hack\hack33
.
.
***
Here's a simple shell using INPUT:
echo off
:loop
INPUT "% " cmd
if %cmd%.==. goto loop
if %cmd%.==exit. goto dos
if %cmd%.==ls. goto ls
%cmd%
goto loop
:ls
dir/w
goto loop
:dos
This could be the cheapest way to con your friends into thinking
that you are running unix.
***
A user-friendly print command:
echo off
set fname=%1
if not %1.==. goto doit
:noarg
INPUT "What file do you want to print? " fname
if %fname%.==. goto noarg
:doit
copy %fname% lpt1
If the user call the batch file with a file name, then the file
will be printed, otherwise the user will be prompted for the name
of the file.
***
There are probably many other uses, but my imagination is quite
limited, if you found a good use for it, please let me know.
CREDIT
Michael Tsang of University of Wisconsin showed me how to locate DOS's
environment space.
Someone posted news to net.micro.pc mentioned the %name% undocumented
feature of DOS; this triggers me to write this program.
AUTHOR
Peter Wu
uucp: ..{ihnp4|seismo|harvard|topaz|allegra|ucbvax}!uwvax!uwmacc!pwu
arpa: uwmacc!pwu@uwvax.ARPA
USmail: 1309 Spring St. #206, Madison, WI 53715
Suggestions and comments are welcome.
[INPUT.C has been added to the Libary. -rag]