Jump to content

Basic DOS programming help


Recommended Posts

Running installs on vmware/virtualpc sometimes seem to have glitches like that. I remember once I tried a setup and it didn't run my start.cmd (from GUIRunOnce) at all... It seems that VirtualPC has it's share of glitches as well. If it works on a real PC... I guess it's all that really matters.

Link to comment
Share on other sites


Thanks, I figured a way around that problem

CHOICE /C:YN /T:Y,60 Voulez-vous installer les logiciels avances
if errorlevel 2 goto cleanup
if errorlevel 1 goto advanced
goto advanced

So now, in case an errorlevel other than no (2) will continue straight with the install :thumbup

Link to comment
Share on other sites

@crahak

You are perfectly right in saying that choice.com is the most logical solution, and again you are right when you say that it is not possible to mimic the choice.com behaviour by batch commands only.

Still, it is possible if you can use a small portion of VBScripting.

The example I posted is, as said, a poorman's possibility, nothing more, it does work, you need to press Control+C to break the execution to be able to send the Yes or No.

@Thauzar

not sure I understant how this works but I trust you it does, I just want to clarify my understanding of the method.

You said:

QUOTE 

l.1 IF "%1"=="Y" GOTO Yes

l.2  IF "%1"=="N" GOTO No

l.3  ECHO Yes or No? Press Y or N followed by the Enter key . . .

l.4  ECHO DEFAULT ANSWER IN ABOUT 10 seconds will be YES....

l.5  ECHO @%0 Y > Y.BAT

l.6  ECHO @%0 N > N.BAT

l.1 if a variable named %1 exists and is equal to Y then it goes to yes

l.2 if a variable named %1 exists and is equal to N then it goes to no

BUT where does this variable come from? and where does the Y or N comes?

l.3 only at this moment we are asking the user to pres Y or N, and where is this information going? how is it related to the %1 variable seen before?

l.5 and 6 are chineese to me and I really don't know why they are there.

When you call the .bat the first time, you do so without passing parameters, so the I.1 and I.2 are just ignored.

I.3 and I.4 are just messages to the user and can be changed.

I.5 and I.6 are the interesting part, let us take I.5 for example:

the command ECHO @%0 Y > Y.BAT does the following:

1) The echo sends everything until the > to the object on the right of the >, so it actually creates a file named Y.BAT and writes in it

2) the @ is just as hte Echo Off command

3) the %0, parameter 0, is the name of the batch file is executing, in this case YN

4) Y is the 1st parameter passed

5) So you are actually creating a batch file called y.bat that invokes your original batch (YN) passing the Y as 1st parameter.

6) When you input Y followed by enter, you execute this Y.BAT file, calling YN.BAT and feeding it with the Y, that this time is filtered by I.1, and so the result is going to the :Yes label.

I.6 does the same for No.

Hope the above is clear enough.

One note, in using choice, you should make a trap to make sure that the user does not press a letter different from Y or N.

A good example is here:

http://www.ericphelps.com/batch/samples/sleep.txt

jaclaz

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...