Do not start a windows .bat file upon Enter

Microsoft Windows xp professional w/serv...
June 27, 2010 at 20:50:44
Specs: Windows XP, Duo CPU P8400
I do not want to start the processing of a windows batch file when the user presses Enter key. I t only starts procesing when the user types 'Y' in the command line.

Right now sometimes pressing Enter is starting the execution of the batch file, sometimes it is working as expected.

Code:
set /p OPTION=Batch Process will start now. Please type Y to continue.
IF /i "%OPTION%" EQU "y" GOTO START


See More: Do not start a windows .bat file upon Enter

Report •

#1
June 28, 2010 at 05:37:39
@echo off & setLocal EnableDELAYedeXpansion

set /p C=what
if /i !C! neq y echo no && goto :eof


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

M2


Report •

#2
June 28, 2010 at 06:30:47
Thank you for your prompt reply.

I added
setLocal EnableDELAYedeXpansion

and also the statement:
if /i !C! neq y echo no && goto :eof

but still it does not work. As soon as I press enter key it starts proessing- which I don't want. I only want it to be processsed if the user types Y.


Report •

#3
June 28, 2010 at 06:51:55
Post the batch.


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

M2


Report •

Related Solutions

#4
June 28, 2010 at 07:07:26
Here i am posting the batch file:


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

@echo off

SETLOCAL EnableDelayedExpansion

set JAVA_HOME=$JAVA_HOME$

set CMD=%1%
set PARAM=''

IF /i "%CMD%" EQU "-AAA" GOTO RUN
IF /i "%CMD%" EQU "-BBB" GOTO RUN1

:INFO
echo Usage:
echo This is a program to welcome everyone to our product.
echo
GOTO EXIT_CMD

:RUN1
if %2%.==. GOTO INFO
set PARAM=%2%


:RUN
set JAVA_PGM=%JAVA_HOME%\bin\java
if not exist "%JAVA_PGM%" set JAVA_PGM=java
set /p OPTION=This Process will start now. Please type Y to continue.
IF /i "%OPTION%" EQU "y" GOTO START
IF /i "%OPTION%" NEQ "y" GOTO EXIT_CMD

:START
"%JAVA_PGM%" -Dlog4j.configuration=log4j_Hello.xml -Xms128m -Xmx128m -jar ISLM\Hello.jar %CMD% %PARAM%
echo Hello processing completed.

:EXIT_CMD

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

Thank you so much for your time.


Report •

#5
June 28, 2010 at 07:26:23
I don't know what this is trying to do:

set CMD=%1%

If it's a variable by the name of 1, is it set? If what you want is to use the first command line parameter, use %1, not %1%.

Either way, avoid special words, like CMD.


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

M2


Report •

#6
June 28, 2010 at 08:35:27
Thank you.
I made the changes suggested. But still it is doing the samething as before .

Once the following prompt gets displayed -
This Process will start now. Please type Y to continue.

If th user presses Enter key instead of typing Y, the .bat file starts processing.


Report •

#7
June 28, 2010 at 08:40:09
Post it


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

M2


Report •

#8
June 28, 2010 at 12:51:59
Here I am posting the script again with the changes suggested:
================================

@echo off

SETLOCAL EnableDelayedExpansion

set JAVA_HOME=$JAVA_HOME$

set CMDARG=%1
set PARAM=''

IF /i "%CMDARG%" EQU "-AAA" GOTO RUN
IF /i "%CMDARG%" EQU "-BBB" GOTO RUN1

:INFO
echo Usage:
echo This is a program to welcome everyone to our product.
echo
GOTO EXIT_CMD

:RUN1
if %2%.==. GOTO INFO
set PARAM=%2


:RUN
set JAVA_PGM=%JAVA_HOME%\bin\java
if not exist "%JAVA_PGM%" set JAVA_PGM=java
set /p OPTION=This Process will start now. Please type Y to continue.
IF /i "%OPTION%" EQU "y" GOTO START
IF /i "%OPTION%" NEQ "y" GOTO EXIT_CMD


:START
"%JAVA_PGM%" -Dlog4j.configuration=log4j_Hello.xml -Xms128m -Xmx128m -jar ISLM\Hello.jar %CMDARG% %PARAM%
echo Hello processing completed.

:EXIT_CMD
================================


Report •

#9
June 28, 2010 at 14:42:51
Beats me. It didn't start unless I typed y.

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

What is this trying to do?

if %2%.==. GOTO INFO


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

M2


Report •

#10
June 28, 2010 at 16:29:45
sounds like external environmental interference possibly.
I've learned, after MUCH profanity and frustration, to always
clear a variable just prior to set /p:
set xx=
set /p xx=enter param:

also, as M2 is wondering, what's with %1%, %2%?
if these are cmd-line parms, they should not have the trailing percent, just: %1
%2
it doesn't seem to hurt anything, but it's confusing...

(edit: looks like you corrected that syntax, cool!)
also, "choice" is almost always an option for simple inputs. (see: choice /?)


Report •

#11
June 28, 2010 at 16:44:04
H:\>choice /?
'choice' is not recognized as an internal or external command,
operable program or batch file.

This is pretty much a stock WinXP SP3 build; I'm not sure what versions of Windows has a version of CHOICE build it.

Report •

#12
June 28, 2010 at 18:43:47
"almost always, anyway! :-D

Report •

#13
June 28, 2010 at 20:04:51
I stole my CHOICE from Win Server 2003 ;-)

Insomniac at large


Report •

Ask Question