Try this:
@ECHO OFF
if [%1] == [] goto error
rem your batch code goes here
goto :eof
:error
for /l %%i in (1,1,12) do echo.
echo There has been an error!
for /l %%i in (1,1,11) do echo.
ping localhost >nul
Or this
@echo off
if [%1]==[] echo an error&pause&goto :EOF
You can use a simple IF test, but this can be problematical should
the parameter may contain "quoted strings" including [Space]s or
other delimiters. This variant may help avoid such problems:
Lines that don't begin with two spaces have wrapped accidentally
====Begin cut-and-paste (omit this line)
@ECHO OFF
SETLOCAL&(SET CHECKpar=%1)
IF NOT DEFINED CHECKpar (ECHO. Parameter is needed.&GOTO :EOF)
ECHO. Parameter supplied was: %1
====End cut-and-paste (omit this line)
Simulated Win2000 for study/demo use. Cut-and-paste as Batch text file.
Batch file troubleshooting: http://www.allenware.com/find?UsualSuspects
--
William Allen
Free interactive Batch Course http://www.allenware.com/icsw/icswidx.htm
Batch Reference with examples http://www.allenware.com/icsw/icswref.htm
From email address not checked. Contact us at http://www.allenware.com/
From 93) How do I check if my script was given a parameter?
133666 Sep 3 2005 ftp://garbo.uwasa.fi/pc/link/tscmd.zip
tscmd.zip Useful NT/2000/XP script tricks and tips, T.Salmi
Back to the very basics, with some additions. Below is an example
with three different options, demonstrating an important pitfall
("") and a useful feature (~) on the side
@echo off & setlocal enableextensions
::
if not [%1]==[] echo %1
if not [%1]==[] echo %~1
::
set par1=%1
if defined par1 echo %1
::
if not "%1"=="" echo %1
::
endlocal & goto :EOF
Example output
C:\_D\TEST>cmdfaq "a b"
"a b"
a b
"a b"
b""=="" was unexpected at this time.
The option, also pointed to by William (Allen), is the safest
set par1=%1
if defined par1 echo %1
All the best, Timo
--
Prof. Timo Salmi ftp & http://garbo.uwasa.fi/ archives 193.166.120.5
Department of Accounting and Business Finance ; University of Vaasa
mailto:t...@uwasa.fi <http://www.uwasa.fi/~ts/> ; FIN-65101, Finland
Timo's FAQ materials at http://www.uwasa.fi/~ts/http/tsfaq.html