Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Mailing Lists -> Oracle-L -> RE: show prompt and accept variable in NT/2000 bat file???
In W2K it is easy, you can use set/p - type set/? to get the help and see below.
H:\>set/p fred=[input value for fred]
[input value for fred]oracleis?
H:\>echo %fred%
oracleis?
H:\>
Or you can call sqlplus and have sqlplus do the prompting and then have it host out to the bat file and pass in the parameters. Or you could Perl or a Unix emulator or I imagine their are many shareware / freeware utilities.
Under NT4 other options are not easy and I have listed a number of ways and links that show how you can achieve this:
Or from a Tom Lavedas posting on the newsgroup alt.msdos.batch.nt
(dated Tue, 05 Jun 2001 09:04:04 -0400 entitled "prompting for a parameter"
"
Old problem - batches were initially assumed to run unattended -
therefore, there was no need for user interaction. However, in the
PC/Windows environment, they are useful for scripting many redundant
tasks, even some that require/benefit user interaction.
MS finally added recognized this fact by adding the /P (prompt) functionality to the SET statement in Win 2000 (but not before that). So, if you are in a pure Win 2000 environment, type SET/? at a command prompt to get information on the use of the /P switch.
If you are using NT 4 or are in a mixed NT/2000 environment, there is no 'perfect' solution. I have been interested in the subject of user input for a long time and have developed and collected various techniques, which I offer for your consideration:
For example ...
Dim Input Input = InputBox("Enter your name") MsgBox ("You entered: " & Input)
(see http://msdn.microsoft.com/scripting/default.htm to get started)
4. A variation on the theme of 3 above is a hybrid WSH script/batch
function
:: InWSH.bat - A WSH/Batch hybrid string input routine.
:: Requires Windows Script Host version 1.0 or later.
:: Use optional command line argument UCASE to convert
:: input to all uppercase or LCASE for lowercase.
:: With WSH V2+, EVAL allows math operations, as well.
:: Tom Lavedas <lavedas_at_pressroom.com>
:: http://www.pressroom.com/~tglbatch/
@echo off
Set _T=%temp%\~tmp
echo Set oFS=CreateObject("Scripting.FileSystemObject")>%_T%.vbs
Echo oFS.OpenTextFile("CON",2).Write "Enter a string: ">>%_T%.vbs
echo S=%1(Trim(oFS.OpenTextFile("CON",1).Readline))>>%_T%.vbs
echo Wscript.Echo "set Input="+CStr(S)>>%_T%.vbs
cscript.exe //nologo %_T%.vbs > %_T%.bat
for %%v in (%_T%.bat del) do call %%v %_T%.???
set _T=
% For Example % echo You typed %Input%
If you call this with a single command line parameter of Ucase or LCase, it will return the string input by the user in the appropriate case. If you have WSH v5.1+ and use EVAL as the command line argument, it will do math operations as well, as in ....
C:\> inwsh eval
Enter a string: 11 * 12
You typed 132
This approach will work with Win 98 and Win 2000 and probably NT right out of the box.
5. In Win2K the following works:
SET /P variable=[promptString]
6. Finally, this NT specific approach, originally given by Walter
Zachery, improved and supplied by Clay Calvert, ....
@echo off
echo.
echo Enter Input:
for /f "tokens=*" %%a in (
'format/f:160 a: ^|find "..."') do set Input=%%a
set Input=%Input:~30%
This approach will spin the floppy drive, but won't change anything. The drive does not need to be occupied.
Tom Lavedas http://www.pressroom.com/~tglbatch/ "
I have seen a web site showing how to do it using label (similar to the format command).
You Can also use choice command - available from ftp://ftp.microsoft.com/Services/TechNet/Windows/msdos/RESKIT/suppdisk/choice.com
And from another alt.msdos.batch.nt posting:
"
Date: Tue, 20 Feb 2001 16:28:40 -0800
...
Here's one way that will work in WinNT4.0. If you are using Win2000,
you can use 'SET /P' instead.
==========begin file C:\cmd\TEST\ZZZINPUT.CMD ==========
001. @echo off 002. echo. 003. call rdstring ZQusername "Please enter your name:" 004. call rdstring ZQuserphone "Phone:" 005. call rdstring ZQaddress1 "Street Address:" 006. call rdstring ZQcity "City:" 007. call rdstring ZQstate "State:" 008. call rdstring ZQZip "ZIP Code:" 009. set ZQ 010. goto :EOF 011. :EOF
==========begin file C:\cmd\TEST\RDSTRING.CMD ==========
001. @echo off 002. :: 003. :: based on method originally provided by Walter Zachary 004. :: and modified by Tom Lavedas 005. :: 006. :: syntax: call rdstring (varname) "your prompt in double quotes" 007. :: 008. setlocal 009. set target=%1 010. set myprompt="""%2""" 011. set myprompt=%myprompt:""""=% 012. echo. 013. echo %myprompt% 014. for /f "tokens=*" %%a in ( 015. 'format/f:160 a: ^|find "..."') do set input=%%a 016. set input=%input:~30% 017. endlocal&set %target%=%input%&goto :EOF 018. :EOF 019.
eg 1 "convoluted" freeware option is to use ask from http://www.kik-it.com to put the response into a text file and then parse that with for command.
Regards,
Bruce Reardon
-----Original Message-----
Sent: Friday, 1 March 2002 4:29
Hi,
How to show prompt and accept variable in NT/2000 bat file?
I'd like to do something like:
Inside bat file
Thank you!
Janet
-- Please see the official ORACLE-L FAQ: http://www.orafaq.com -- Author: Reardon, Bruce (CALBBAY) INET: Bruce.Reardon_at_comalco.riotinto.com.au Fat City Network Services -- (858) 538-5051 FAX: (858) 538-5051 San Diego, California -- Public Internet access / Mailing Lists -------------------------------------------------------------------- To REMOVE yourself from this mailing list, send an E-Mail message to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in the message BODY, include a line containing: UNSUB ORACLE-L (or the name of mailing list you want to be removed from). You may also send the HELP command for other information (like subscribing).Received on Thu Feb 28 2002 - 18:58:29 CST
![]() |
![]() |