Denney Posted August 24, 2004 Posted August 24, 2004 Can someone tell me what is wrong with the following statement...cls%systemdrive%\MSA\UTILITIES\CMDOW.EXE @ /VISset /p floppy="Do you have any MSA update floppies (y/n)? "%systemdrive%\MSA\UTILITIES\CMDOW.EXE @ /HID:UPDATEFLOPPYif %floppy%==y ( echo. >> %log% echo COMPSETUP.CMD (20): Setting up MSA floppies: >> %log%)No matter what I answer the floppy question with, the command file dies on me. No errors or anything.I'm only new to using if statements like this but to me, this should work. I originally thought it could have been because I was using nested IF statements but even the simplest one like this won't work. Can somebody help me?
GreenMachine Posted August 24, 2004 Posted August 24, 2004 I suspect the reserverd characters in the echo statement Colon [:] and parens [()]
Denney Posted August 24, 2004 Author Posted August 24, 2004 Hmm... I've used lines like the following throughout my command file and they all work fine:echo COMPSETUP.CMD (5): Starting computer setup. > %log%This problem has only started since I started using "()" in my IF statements.I'm sick and tired of having to manage dozens of IF statements when I should be able to put all my commands into one statement.
evilvoice Posted August 24, 2004 Posted August 24, 2004 raverod, check this topic out...one i need your help on the question for you...but 2, because maybe the thing at the end will help you...hereif you could answer my question, great, but here is the way I think you should change your if statementif %floppy%==y (echo.echo COMPSETUP.CMD (20): Setting up MSA floppies:) >> %log%and now for the reason why it works this way, i think in theory...lets say everything for if is if this then this...well the () is the first part of the last this, but you never tell it what to do with the ()...ie, you never finish "then this" of the if statement.
Denney Posted August 24, 2004 Author Posted August 24, 2004 I answered your question and tried your suggestion but that didn't work. I'm totally lost as to what this problem could be. :S
Denney Posted August 24, 2004 Author Posted August 24, 2004 BAH! GreenMachine, you are the man!Removing the () around my echo statement INSIDE the IF statement fixed it. After all that.Edit: ****, that also means I cannot have nested IF statements.
evilvoice Posted August 24, 2004 Posted August 24, 2004 disregard post...tested it and it works, good job GM
Denney Posted August 24, 2004 Author Posted August 24, 2004 Well, the nested IF statements has buggered my whole idea up really. I really wanted to nest those things. Ahwell...What I've done to fix my IF statement is to change the "()" to "[]". Answering "n" or anything other than "y" and it skips the IF statement fine.I don't seem to have any problems with the ":".
evilvoice Posted August 24, 2004 Posted August 24, 2004 what do you mean by nested...gimme example...btw, you dont even need the () or [] or anything...if you do not answer y it basically quits
Denney Posted August 24, 2004 Author Posted August 24, 2004 @evilvoice: After my IF statement I have a whole lot more things and the batch continues fine. I didn't post the entire file because that's not the problem. When I say nested, I mean something like this:if %floppy%==y (echo. >> %log%echo COMPSETUP.CMD [20]: Setting up MSA floppies: >> %log%if not exist A:\MSAXP.FPY ( echo COMPSETUP.CMD [23]: No MSA update floppy detected. >> %log% cls %systemdrive%\MSA\UTILITIES\CMDOW.EXE @ /HID echo Please place an MSA update floppy into your A: drive. pause %systemdrive%\MSA\UTILITIES\CMDOW.EXE @ /HID))Edit: DOH! Nevermind. It was because I wasn't UNHIDING my command file. LOL.
evilvoice Posted August 24, 2004 Posted August 24, 2004 clsCMDOW.EXE @ /VISset log=c:\temp1.logset /p floppy="Do you have any MSA update floppies (y/n)? "CMDOW.EXE @ /HID:UPDATEFLOPPYif %floppy%==y (echo.echo "COMPSETUP.CMD (20): Setting up MSA floppies:"if NOT exist a:\msaxp.fpy (echo "COMPSETUP.CMD [23]: No MSA update floppy detected."cls%systemdrive%\MSA\UTILITIES\CMDOW.EXE @ /VISecho Please place an MSA update floppy into your A: drive.pause%systemdrive%\MSA\UTILITIES\CMDOW.EXE @ /HID)) > %log%that works...this is what temp1.log contains."COMPSETUP.CMD (20): Setting up MSA floppies:""COMPSETUP.CMD [23]: No MSA update floppy detected."Please place an MSA update floppy into your A: drive.Press any key to continue . . .
evilvoice Posted August 24, 2004 Posted August 24, 2004 just noticed your reply...ya beat me...its really 6 to 1 1/2 a dozen to the other.
sleepnmojo Posted August 24, 2004 Posted August 24, 2004 BAH! GreenMachine, you are the man!Removing the () around my echo statement INSIDE the IF statement fixed it. After all that.Edit: ****, that also means I cannot have nested IF statements. Its actually a problem with the parser here. When it encounters the ), it thinks it is finished the if statement. Which is why you have a problem.When it comes to nesting, you shouldn't have a problem. I do it all the time. One way to get around this, is to make it a single line if statement.if %floppy%==y echo. >> %log%if %floppy%==y echo COMPSETUP.CMD (20): Setting up MSA floppies: >> %log%
Denney Posted August 25, 2004 Author Posted August 25, 2004 Well, this is what I've found:I can nest IF statements:if a==b (if b==c (d))I can include a for statement inside an IF statement:if a==b (for %%i in (a b c d) do (e))I can include an echo statement with () IF they're in quotes:if a==b (echo "Something (lala)")I can't include an echo statement with ():if a==b (echo Something (lala))Don't ask me how this all works but I've fixed my problems now so it's all OK.And the []'s look better than the ()'s in my log file anyway.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now