|
Answer» Hi, The question may appear stupid but I'm newbie in MS-Dos batches... I'd like to test if a parameter pasted in my command line of my batch is PRESENT or not, I tryed:
IF "%1X"=="X" GOTO :syntaxe
The problem is when my parameter %1 still have quotes... Thanks in advance for your answers, ind57
PS: WinXP SP2 French, Dell latitude D520, 1go, CORE Duo.This is how we check if a parameter is blank
If "%2"=="" goto blank2
Moi je suis rosbif, mais j'aime bien Indochine!
Thanks contrex but it doesn't solve my problem. My command line is: run.bat "c:/test java/"
When I use: echo %1 There is: "c:/test java/"
So when I test: IF "%1"=="" THEN ... There is the message: java""=="" était inattendu. which could be translated in English by: java""=="" was unattempted
In fact there is no problem when the parameter is not between quotes, but I don't KNOW how checking if it is between quotes or not.
ind57
PS: t'as plutôt un bon accent Here is how to solve the problem. The message you got that qqch était inattendue, in English versions of Windows will be "was unexpected at this time".
1. When you pass a parameter in quotes, which you need to do if it has spaces in it, you will have a problem in the batch file if you need to do a test such as this
if "%n"==""
because the quotes already in the parameter are added to the quotes in the "%n" and that makes the batch file crash. It also crashes if you do this
if %n==""
2. Les telles situations étaient prévues by the authors of the batch language (Windows 2000 and XP I mean). The following allows to remove quotes from a parameter
Suppose that %1 is "Nicola Sirkis" (with quotes)
then %~1 is Nicola Sirkis (without quotes)
The tilde character "~" (I don't know its name in French), when placed before the parameter NUMBER (or a letter if it is a FOR variable), removes any quotes surrounding that parameter or variable.
Consider the following batch file
Code: [Select]@echo off echo passed parameter is %1 echo dequoted parameter is %~1
if "%~1"=="" echo parameter 1 is blank
I called it qparam.bat
here are its results
Code: [Select] F:\test\param>qparam Nicola Sirkis passed parameter is Nicola dequoted parameter is Nicola
F:\test\param>qparam "Nicola Sirkis" passed parameter is "Nicola Sirkis" dequoted parameter is Nicola Sirkis
F:\test\param>qparam passed parameter is dequoted parameter is parameter 1 is blank
Thank you very much Contrex, c'est pile poil ce que j'voulais! merci ENCORE, ind57
|