Jump to content

Recommended Posts

Posted

Can someone tell me what is wrong with the following statement...

cls
%systemdrive%\MSA\UTILITIES\CMDOW.EXE @ /VIS
set /p floppy="Do you have any MSA update floppies (y/n)? "
%systemdrive%\MSA\UTILITIES\CMDOW.EXE @ /HID
:UPDATEFLOPPY
if %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?


Posted

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. :(

Posted

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...

here

if you could answer my question, great, but here is the way I think you should change your if statement

if %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.

Posted

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

Posted

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. :(

Posted

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 ":".

Posted

@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.

Posted

cls
CMDOW.EXE @ /VIS
set log=c:\temp1.log
set /p floppy="Do you have any MSA update floppies (y/n)? "
CMDOW.EXE @ /HID
:UPDATEFLOPPY
if %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 @ /VIS
echo 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 . . .

Posted
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%

Posted

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. :P

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...