Batch script issue

Discussion in 'Software' started by Mister Fox, Feb 9, 2012.

  1. Mister Fox

    Mister Fox Private E-2

    I've been using batch files for a while now, and I'm at the level where I know all the basic stuff. However, one thing that annoys me is that I cannot set an input that is more that 1 word long.
    For example, when using "set /p web=", the input can only be 1 word, becuase in the next lines where I specify actions, "if %web%==xxxx goto yyyy", the second word has to be a command. If I want to make the input "launch missiles" (for a game I'm making), an error comes up that says ' "missiles" is not a valid command....ect.'
    Does anyone know how to make an input that it longer than 1 word? I understand that batch files have many barriers and limitations, but is 1 word inputs one of them?


    Also, I just joined. YAY!
     
  2. PC-XT

    PC-XT Master Sergeant

    I sometimes forget to do this, myself, because I'm used to the old DOS 3 methods, but this should work:
    Code:
    if "%web%"=="xxxx" goto yyyy
    The quotes let spaces be included, and should be used in every test that could contain multiple words.
     
  3. Mister Fox

    Mister Fox Private E-2

    When I use that code, it comes up as "The syntax of the command is incorrect"
    I am using it like this:

    set /p web=

    if "%web%"=="xx xx" goto Y

    :Y
    echo blah blah blah....
     
  4. FineJungThingy

    FineJungThingy Private E-2

    >> it comes up as "The syntax of the command is incorrect"

    Have to determined exactly which line of code gives that response?

    I tried your code on Windows XP and Windows Vista and it worked fine, no error message.

    What operating system are you trying this code on?

    The pages linked below have a lot of batch programming info and/or samples, maybe could help you.

    http://www.robvanderwoude.com/batchfiles.php

    http://www.macalester.edu/~fines/batch_tricks.htm

    Once in a very long while somebody asks me for help with batch programming, mostly to modify or maintain code dating back from the time of the Pharaohs. I believe it is possible that the Mayans used a batch program to determine their now-infamous calendar, and perhaps that's why 2012 is not likely to play out as some speculate.....the Mayans didn't fully comprehend the impact of Y2K.
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds