Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsWindows Server 2003Windows 2000Windows NTSmall Business ServerVirtual ServerExchange ServerIISHost Integration ServerISA ServerSMSWSUSMOMWindows Media ServerSecurityCertification
Related Topics
SQL ServerMS WindowsMS OfficePC HardwareMore Topics ...

Windows Server Forum / Windows 2000 / Command Prompt / June 2008

Tip: Looking for answers? Try searching our database.

how to write embeded if statement

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
thinktwice - 19 Jun 2008 14:13 GMT
i have written something like:
if not (%1) == () (
if not %1 == "" (set SENDER=%1))

but it doesn't work, it's invalid if statement
Tom Lavedas - 19 Jun 2008 14:35 GMT
> i have written something like:
> if not (%1) == () (
> if not %1 == "" (set SENDER=%1))
>
> but it doesn't work, it's invalid if statement

This one is tricky - it took a minute to figure out.  Even though it
appears that the blank condition of the replaceable parameter, %1, is
being tested; the syntax of the second part of your compound statement
is being parsed, anyway.  This is because the command processor is a
single pass processor and the parentheses make the multiple lines a
single statement (all of which is evaluated at one time). Therefore,
if %1 is empty, a syntax error results.

Try something like this ...

if not (%1) == () (
if not [%1] == [""] (set SENDER=%1))

Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/
Dean Wells (MVP) - 19 Jun 2008 15:14 GMT
>i have written something like:
> if not (%1) == () (
> if not %1 == "" (set SENDER=%1))
>
> but it doesn't work, it's invalid if statement

What are you trying to determine by the condition?

... I can guess of course, but I'd like to make sure I'm not incorrectly
inferring your goal.

Signature

Dean Wells [MVP / Directory Services]
MSEtechnology
[[ Please respond to the Newsgroup only regarding posts ]]
R e m o v e    t h e    m a s k    t o    s e n d    e m a i l

thinktwice - 20 Jun 2008 05:30 GMT
On 6月19日, 下午10时14分, "Dean Wells \(MVP\)"
<dwe...@maskmsetechnology.com> wrote:

> >i have written something like:
> > if not (%1) == () (
[quoted text clipped - 12 lines]
> [[ Please respond to the Newsgroup only regarding posts ]]
> R e m o v e    t h e    m a s k    t o    s e n d    e m a i l

thanks for you help, i'm trying to make sure the parameter that passed
to my batch file isn't empty nor ""
Al Dunbar - 20 Jun 2008 06:13 GMT
On 6ÔÂ19ÈÕ, ÏÂÎç10ʱ14·Ö, "Dean Wells \(MVP\)"
<dwe...@maskmsetechnology.com> wrote:
> "thinktwice" <memorial...@gmail.com> wrote in message
>
[quoted text clipped - 16 lines]
> [[ Please respond to the Newsgroup only regarding posts ]]
> R e m o v e    t h e    m a s k    t o    s e n d    e m a i l

thanks for you help, i'm trying to make sure the parameter that passed
to my batch file isn't empty nor ""

try this, then:

if "%~1" EQU "" (
   echo/first parameter is either empty (null, missing) or ""
) else (
   echo/an actual non-null value was passed as the first parameter.
)

This can sometimes be useful too:

(set _param=%~1)
if defined _param (
   echo/an actual non-null value was passed as the first parameter.
) else (
   echo/first parameter is either empty (null, missing) or ""
)

/Al
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.