in my batch file i want to wait for user input for seconds, if user
doesn't press any key during this period then make the default choice.
i have googled for a while, what i know now is i could use ping to
achieve the delay function , but i don't know how to get the user
input during this period?
The closest I can think of is the old Choice.exe program, but it is no
longer supplied with later versions of windows. I think Win NT was
the last one that cam with it.
Or you can try my little home brew that uses a hybrid JScript/batch
approach ...
@set @x=0 /* Batch part
@echo off
setlocal
set "Input="&set delay=10000 %/ milliseconds /%
set /p Input=Enter data here: < nul
for /f "delims=" %%I in (
'cscript //nologo //e:jscript "%~f0" %delay%'
) do endlocal & set "Input=%%I"
if not defined input echo.
echo.For example: "%Input%"
goto :EOF
Jscript part */
var d=WSH.Arguments(0);var t=0;
with(new ActiveXObject("WScript.Shell")){
with(Exec('%comspec% /c(set /p _#=<con&set _#)')){
while(Status==0){
WSH.Sleep(50);t+=50;if(t>d)Terminate()};
if (!StdOut.AtEndofStream) {
WSH.Echo(StdOut.ReadLine().substr(3))}}}
_______________________
Tom Lavedas
Hmm. I believe that NT did not have choice.exe - it was included in 98 and
me.
This hybrid-scripting seems to be a viable approach here. I'd offer two
modifications
1/ add
(set @x=)
directly after the "@echo off" to clean up the environment a little
2/ if not defined input echo.
becomes
if not defined input set input=DEFAULTVALUE
to get closer to OP's ambition.
Not quite a complete solution though - as this requires a CR and CHOICE
worked on the single key-entry.
I'll continue this in your "hybrid scripting" thread in alt.msdos.batch.nt
Try choice.(exe|com)
If you can find a choice.com (or a similar program) use it with
/t[:]c,nn switch
See http://www.netikka.net/tsneti/info/tscmd014.htm
All the best, Timo
--
Prof. Timo Salmi mailto:t...@uwasa.fi ftp & http://garbo.uwasa.fi/
Hpage: http://www.uwasa.fi/laskentatoimi/english/personnel/salmitimo/
Department of Accounting and Finance, University of Vaasa, Finland
Useful CMD script tricks http://www.netikka.net/tsneti/info/tscmd.php
Hi,
You can also use editvar/editv32/editv64 or choose/choose32/choose64
editvar/choose - MS-DOS versions
editv32/choose32 - Windows console x86 versions
editv64/choose64 - Windows console x64 versions
editvar/editv32/editv64 is a utility that lets you interactively edit
environment variables. It has several features many have told me they
have found useful, such as timeout and masked input (displays '*' for
typed characters, useful for entering passwords).
choose/choose32/choose64 is an alternative to the Microsoft 'choice'
program and offers the same feature set with a couple of enhancements.
All programs are freeware, available from my web site:
http://www.westmesatech.com/editv.html
--
Bill Stewart