Questions and answers in batch files

January 9, 2010 at 22:22:59
Specs: Ms-dos
Hi!
I am a newbie in bach programming, and I'm having some truble programming questions and answers into a batch file.

My platform is a 486 with ms-dos 4.01

Example:

@echo off
cls
:quest
echo.
echo.
echo What is the name of our country?
echo (Type your answer and press enter.)
if "usa" goto correct
if "unated states of america" goto correct
if error\incorrect goto quest
:correct
cls
echo Congratulations! You won!
goto end
:end

eh.. wel, my knowledge is limited.
I do however hope to be filled in on the "need to know" in order to make this batch work! :) thanks!
Christian P., norway.


See More: Questions and answers in batch files

Report •


#1
January 10, 2010 at 03:32:17
Hmm... the batch you posted will never work (after removing the incorrect statements) because in plain DOS there is no way to prompt the user to enter a string. That is enabled by the Set /P command you can find in NT batch under XP/2000 or higer systems.

Anyway to learn about batch commands at prompt type e.g. IF /? (to know how to code an if statement) and the same for any command (goto /? set /? and so on).

Not friendly but a good starting point.


Report •

#2
January 10, 2010 at 08:39:08
Wel... Ok.

Sorry about that batch i posted, it was only a bad example to short down the explaining.

But issent there any .exe or .com programms like
query and choice that allows you to type at least a eigth letter answer?


Report •

#3
January 10, 2010 at 09:19:31
Hi,
I don't know how much time you want to invest but the how to is on this page
http://support.microsoft.com/kb/77457

Hope this helps


Report •

Related Solutions

#4
January 10, 2010 at 09:30:05
Stated CHOICE allows to enter just ONE char, there are ways to prompt the user to enter strings even using just plain DOS commands, but they are so tricky, conplex and cumbersome that are far beyond the knowledge of a newbie.

Not to say they are forgotten as bound to obsolete and legacy systems.
In the Open Source clone of DOS, FreeDOS you can freely download and install, the command SET /P is supported jist to enable user prompting.


Report •

#5
January 10, 2010 at 10:58:14
You must be one of the 5 people in the known universe using DOS 4.01.

As IVO says it's posible to do some input via command line params but it's a mess.

DOS 6.22 has CHOICE.COM which may work in 4.01; if not you may want to install 6.22.

Or, as IVO suggests, freeDOS or another, more recent clone might be a better catch.


=====================================
Helping others achieve escape felicity

M2


Report •

#6
January 10, 2010 at 12:16:30
Hahaha! Yes, probably! :D
But i'm also one of the 5 people in the known universe more patient, stubborn and dedicatet.

Annyways, im settelig for the tricky way.
I did a bit of reserch my self, and found this on your page! :)

http://www.computing.net/answers/do...

This is close to what I need. Insted of the asterisks, I want the numbers and\or lethers to be displayd when typed.

I would be very thankfull if you could show me how. :)
Thanks!


Report •

#7
January 10, 2010 at 14:45:13
Hi Christian,

"But i'm also one of the 5 people in the known universe more patient, stubborn and dedicatet."

There's a lot to be said for PS&D.

==========================
This simple bat will show a little of how to process user input without CHOICE.

If you want examples of DOS bat files look for the work of Laura Fairhead, among many others. She knows more about DOS bats than I ever wanted to.
================================
@echo off

if %1'==' goto :syntax

:check name entered
if "%1"=="joe" echo OK
if not "%1"=="joe" echo wrong name

goto :eof

:syntax

echo usage: %0 yourname

:eof

==================================


=====================================
Helping others achieve escape felicity

M2


Report •

#8
January 19, 2010 at 22:19:56
i know this thread is older than creation, but i was experimenting and remembered your post...

@goto aaa
e100 B4 01 CD 21 2C 30 48 4C CD 21
RCX
10
W
Q
:AAA
IF EXIST KEY.COM GOTO :BBB
DEBUG KEY.COM < %0.BAT > NUL 2>NUL
:BBB
::Demonstrates capturing of errorlevel to a printable character...
:Captures everything except:<>= key.com subt.s 48 from the input
:does NOT handle backspace - it can be tested for (216), but not handled
:as a rub-out. User would have to retype from start.
@echo off
set E1=!,#,$,%%,&,',(,+,-,/
SET NUMS=0,1,2,3,4,5,6,7,8,9
set E2=:,;,@
SET CAPS=A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z
set E3=[,],^,_,`
SET SMALLS=a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z
SET E4={,},~
SET TEXT=
:00
SET TEST=
KEY
:: the "reserved words" (ie: not processable due to shell interpretation)
IF ERRORLEVEL 221 IF NOT ERRORLEVEL 222 GOTO :DONE
IF ERRORLEVEL 254 SET TEST=.
IF ERRORLEVEL 216 IF NOT ERRORLEVEL 217 GOTO :BKSPC
IF ERRORLEVEL 252 IF NOT ERRORLEVEL 253 SET TEST=,
IF ERRORLEVEL 250 IF NOT ERRORLEVEL 251 SET TEST=*
IF ERRORLEVEL 249 IF NOT ERRORLEVEL 250 SET TEST=)
IF ERRORLEVEL 242 IF NOT ERRORLEVEL 243 SET TEST="
:space at end of this line!
IF ERRORLEVEL 240 IF NOT ERRORLEVEL 241 SET TEST=
IF ERRORLEVEL 44 IF NOT ERRORLEVEL 45 SET TEST=\
IF ERRORLEVEL 15 IF NOT ERRORLEVEL 16 SET TEST=?
:these can't be handled using SET due to conflicts of interest
:IF ERRORLEVEL 14 IF NOT ERRORLEVEL 15 SET TEST=>
:IF ERRORLEVEL 13 IF NOT ERRORLEVEL 14 SET TEST==
:IF ERRORLEVEL 12 IF NOT ERRORLEVEL 13 SET TEST=<
IF ERRORLEVEL 11 IF NOT ERRORLEVEL 12 SET TEST=;
IF NOT "%TEST%"=="" GOTO :XIT
FOR %%A IN (%E3%,%SMALLS%,%E4%,%E1%) DO IF ERRORLEVEL %%A SET TEST=%%A
IF NOT "%TEST%"=="" GOTO :XIT
FOR %%A IN (%NUMS%,%E2%,%CAPS%) DO IF ERRORLEVEL %%A SET TEST=%%A
:XIT
SET TEXT=%TEXT%%TEST%
GOTO :00
:BKSPC
CLS
ECHO SORRY YOU WILL HAVE TO REENTER FROM SCRATCH
SET TEXT=
GOTO :00
:DONE

to use the script (demo):
echo enter some stuff but not grtrthan, lssthan, or equals!
call gettext
echo here's your text:[%text%]

does not work right on XP and up, but why would you want to anyhows?


Report •

#9
January 19, 2010 at 23:36:55
I think your debug script needs:

N key.com


=====================================
Helping others achieve escape felicity

M2


Report •

#10
January 20, 2010 at 00:12:48
hey,
i put it into cmdline with suppressed error output, so (hopefully) it should work:
debug key.com < blah blah > blah blah
prettymuch same diff... i think...

ps: finally figured out why you wrote your date script as you did, BACKWARD COMPATIBILITY!
i couldn't figure why you hobbled yourself so, then i realized it's intended to be DOS-capable (pre-XP). DUH (me), you stated as much.


Report •

#11
January 20, 2010 at 23:41:10
Hi n,

Somebody else did most of the work. I think it was dtech10.

Hopefully whoever did will jump up and take credit.


=====================================
Helping others achieve escape felicity

M2


Report •

#12
January 21, 2010 at 04:19:53
if "unated states of america" goto correct

Report •


Ask Question