Jump to content

Basic DOS programming help


Recommended Posts

@crahak

I do not want to argue, but in English

"Do you want to install the basic softwares" [Y/N] and goes on with yes after 60 seconds.

is called "delayed execution of a command"

If you think it is better to call it a timeout, do it, you are free, but don't go around teaching others.

jaclaz

I don't go teaching others. Call it whatever you want, it doesn't matter to me. I only commented that waiting won't answer the question with a default value. There is a huge difference between just waiting (a delay and nothing more) and having a command after a second pick it's default option, no matter what you call it.

Or perhaps I missed something you can teach me how to make ping answer yes to choice.com after a 60 seconds?

(time out is just like ping.exe doesn't get the expected answer after the set time, just like it says "Request timed out." It doesn't go saying "delayed execution of the command failed" does it? And as far I know, that was plain english as well - from a dictionnary: "The result if your computer waits more than a certain amount of time when requesting data" - which is the keypress in our case. Even the dictionnary says that... and there's plenty more to quote...)

Link to comment
Share on other sites


Here's a solution that needs no external tools, just run it directly. An example from my unattended batch scripts:

@echo off
TITLE Installing Photoshop CS
COLOR 85
ECHO.


:LOOP
SET Choice=
SET /P Choice="Do you want to install Photoshop CS ? (Y/N)"

IF NOT '%Choice%'=='' SET Choice=%Choice:~0,1%

ECHO.
IF /I '%Choice%'=='Y' GOTO Install
IF /I '%Choice%'=='N' GOTO no
ECHO Please type Y (for Yes) or N (for No) to proceed!
ECHO.
GOTO Loop


:no
ECHO Photoshop CS was not installed >> %systemroot%\Temp\instTime.log
ECHO Finished.
GOTO END

:Install
ECHO Installing Photoshop CS now
ECHO Please wait.....
start /wait %systemdrive%\install\Applications\PS8\setup.exe /QB
ECHO Finished.

GOTO END

:END
ECHO.
EXIT

Link to comment
Share on other sites

Unfortunately there are no simple ways to do that in vbscript... running it with csript will give you possibility to use keyboard input, but not a loop that checks for a keypress, if not, wait and loop until (keypressed or timedout). It would be about 10 lines in turbo pascal...

Link to comment
Share on other sites

I am sorry you take it like this:

If you use choice.com, you have the delay built in in the command.

The point was to have the result without having choice.com, the idea was to have this:

@ECHO OFF
  IF "%1"=="Y" GOTO Yes
  IF "%1"=="N" GOTO No
  ECHO Yes or No? Press Y or N followed by the Enter key . . .

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

  ECHO @%0 Y > Y.BAT
  ECHO @%0 N > N.BAT

::The timing is non exact, the 10000 is roughly 10 seconds
PING 1.1.1.1 -n 1 -w 10000 > NUL
GOTO YES

  GOTO End
  :Yes
  ECHO.
  ECHO You answered Yes
  GOTO End
  :No
  ECHO You answered No
  :End
if exist y.bat del y.bat
if exist n.bat del n.bat

If you try it, you will see that it works.

As Rob puts it, you can use it in emergency only, but it is still a good example of batch "sideways" scripting.

jaclaz

Link to comment
Share on other sites

To finalize the matter, here are other methods by Tino Salmi, NT/2000/XP only:

http://www.uwasa.fi/~ts/http/http2.html#cmdscript

including a vbs one

From ts@uwasa.fi Tue Aug 10 01:00:19 2004
Subject: 19) How can one build a delay / sleep / wait procedure for a script?
Date: Tue, 10 Aug 2004 01:00:19
From: ts@uwasa.fi (Timo Salmi)

 @echo off
 setlocal enableextensions
 echo %time%
 call :ProcDelay 250
 echo %time%
 goto :EOF

 :ProcDelay delayMSec_
 setlocal enableextensions
   for /f "tokens=1-4 delims=:. " %%h in ("%time%") do set start_=%%h%%i%%j%%k
   :_procwaitloop
     for /f "tokens=1-4 delims=:. " %%h in ("%time%") do set now_=%%h%%i%%j%%k
     set /a diff_=%now_%-%start_%
   if %diff_% LSS %1 goto _procwaitloop
 endlocal & goto :EOF

The output e.g:
 D:\TEST>cmdfaq
 10:30:49.84
 10:30:52.34

There is another, makeshift alternative, but it requires that the PC
has TCP/P. For a two second delay one can try to ping oneself as
follows
@echo off
ping -n 3 127.0.0.1>nul
which would produce e.g.
 D:\TEST>cmdfaq
 15:24:47.57
 15:24:49.62
As you see, it is not dead accurate. Not that it is essential.

Furthermore, you could have
 @echo off & setlocal enableextensions enabledelayedexpansion
 echo WScript.Sleep 1000 > %temp%\tmp$$$.vbs
 echo %time%
 cscript //nologo %temp%\tmp$$$.vbs
 echo %time%
 for %%f in (%temp%\tmp$$$.vbs) do if exist %%f del %%f
 endlocal & goto :EOF
which would produce e.g.
 D:\TEST>cmdfaq
 13:13:03.00
 13:13:04.07

I tried a Google search for "timeout", but found the above searching for "delay"....

:whistle:

jaclaz

Link to comment
Share on other sites

@jaclaz

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:

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.

for the rest I think I understand the ping, and :yes :no section are easy to get.

Link to comment
Share on other sites

I tried a Google search for "timeout", but found the above searching for "delay"....

:whistle:

jaclaz

It's too bad you don't understand what he wants in the first place. You're the only one stuck on wording. I only tried to tell what he actually wants. You just found tricks for delays and just that, which is NOT what he wants, and now you come back with more delays.... If he did say "I want delays", we could all have provided him with delays. (this is getting far too long and pointless, and I hate to have to say all this all over again for nothing).

What he wants is the wait.com to do what it does, but for 60 seconds instead of 10. Not x seconds wait before or after the command... So effectively, the wait.com times-out or whatever. There are no delays. A delay does just that, wait, and it's not what he wants. Hopefully I don't have to explain it again.

Link to comment
Share on other sites

@crahak now I'm all confused, the CHOICE /T:Y,10 is asking wait.com to wait for the time specified, then times out and the batch files continue. Right? Now if I do PING 1.1.1.1 -n 1 -w 10000 > NUL it sends out a PING command, delayed for 10 seconds, then goes on with the rest of the script. Right?

So from what I understand, if i'm right, the only difference between does 2 is that the first one is embeded in the CHOICE.com file, which I have to add (this should never have been taken out of windows) and the second one sends a useless ping request about a fictive machine only to kill time before continuing.

So if I'm right, both are the same while being different, and I don't understand what's the big fuzz about this.?

Link to comment
Share on other sites

Exactly! You got it right.

If you try his script with the ping and press N+enter sometime just before it ends (I counted up to 10 slow), it still defaults to Yes... And then after it enters N+enter on the command prompt and it tells me bad command of course... plus it still waits after I pressed enter (making you wonder if it crashed or didn't take your input or ?), and oh, it doesn't work with lowercase letters - and you don't notice until you find out it picked the wrong one (and depending on what it does - might force you to reinstall?). Also when you read it again in a year from now might be less obvious to understand than a simple and clean choice.com line in your batchfile. If you just wanted it to wait instead of giving the user more time to answer, then sleep.exe works well too... There are choice.com clones (a quick web search found one easily)

Link to comment
Share on other sites

No, choice.com works perfectly well, as I told, I use

CHOICE Install the **** apps? /C:YN /T:Y,60 and it does exactly what I wanted

Install the **** apps? [Y/N] _

and after about a minute it goes on with the yes. That's why choice.com should never have been removed. All I wanted was that if I'm not sitting there in front of my computer because I DO NOT want to install the default apps I added myself on my unattended xp cd, I would have more then enough time to press N, if i'm not there it's because I don't care and want the default apps installed because i'm the one who made this **** cd hehehe.

Still, I'm curious about those custom CHOICE.com you are talking, what do they do more? My version of CHOICE.com from DOS 6 or 7 supports 60 seconds timeouts.

Link to comment
Share on other sites

Ok then :)

I found this clone too http://www.usfamily.net/web/wpattinson/wil...util/choice.zip that does that, it's freeware also. It has a couple extras too (multiline prompts, and supports pressing ESC and ENTER... ) Same syntax as well.

And for the record, I don't recall being un-friendly whatsoever to anyone.

To me, delayed execution of a command would be like:

sleep 10 (or ping, or whatever you want)

format c: /q

will format your HD, and it sure is delayed by 10 seconds...

choice /C:YN /T:Y,60

will not delay anything (but it will wait for keypress - and timeout if you don't press a thing).

Link to comment
Share on other sites

I'm having a very strange error while testing my installation cd. On my real computer, if I take out every real install command and only keep the processing structure, everything goes ok, choice runs and everything is perfect. With the same structure, but during real installation on Virtual PC, each and every time, choice does not get run thus not installing the applications. What's the problem?? I kept the same choice command and choice.com is always in the same folder as the batch file, in C:\Install\Applications ($OEM$\$1\Install\Applications\)

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...