Results 1 to 5 of 5
  1. #1
    Star Lounger
    Join Date
    Nov 2002
    Location
    Port Talbot, Wales
    Posts
    71
    Thanks
    0
    Thanked 0 Times in 0 Posts

    DOS Variables (Windows XP)

    I don't really know how to explain this. If you create a shortcut to a batch file in Win95/98 and then alter the shortcuts properties by adding a " ?" at the end of the path and file name it makes windows call up an Enter Variable box before the batch file runs. What ever you type in variable box is then stored in the "%1" variable for use in the batch file. Anyone know of a way of doing this in XP? Or a way to ASK the user to specify a variable, I.e. A Path, Filename or Password! I know how to ask it for keys but i want the equivulent of a stored String in VB.

    Thanks
    Jamie

  2. #2
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    Cincinnati, Ohio, USA
    Posts
    7,089
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: DOS Variables (Windows XP)

    Do you need to prompt the user for input, or can you pass the value to the batch file using a static value? I use the IF statement to check for a valid variable that will determine the execution of certain subroutines in a command script. If the user's choice isn't valid, it calls a :SYNTAX label to let them know the proper use.

    I haven't tried it, but perhaps you could use the old CHOICE.COM in your script. It may not run properly or at all under CMD.EXE, and COMMAND.COM is slow as molasses but might work.

    Historically, getting input in a batch file has been a difficult task, but there are ways if you're willing to spend the time. <img src=/S/smile.gif border=0 alt=smile width=15 height=15>
    -Mark

  3. #3
    5 Star Lounger
    Join Date
    Dec 2002
    Location
    Perth, Western Australia, Australia
    Posts
    730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: DOS Variables (Windows XP)

    You can use the <img src=/S/new.gif border=0 alt=new width=35 height=15> enhanced SET command to get user input. Not quite the same as the <img src=/S/question.gif border=0 alt=question width=15 height=15> you had under w98, but should achieve much the same result. You'll need to modify your batch files slightly, since they'll be getting the user input, rather than having it passed as a command line parameter.

    Insert a set command, eg "set /p userinput=Please enter filename", at the start of your batch file, and then use the %userinput% environment variable in lieu of %1 in the rest of the batch file.

    For more details do a "set /?" in a cmd window. And you may find the <!post=Batch Files,203360>Batch Files<!/post> and <!post=Command Line Commands,213807>Command Line Commands<!/post> threads interesting, maybe even adding to your batch armoury.. <img src=/S/grin.gif border=0 alt=grin width=15 height=15>
    <font face="Comic Sans MS" color="blue">TimOz</font>
    <img src=/S/flags/Finland.gif border=0 alt=Finland width=30 height=18> <img src=/S/flags/Australia.gif border=0 alt=Australia width=30 height=18>

  4. #4
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    Cincinnati, Ohio, USA
    Posts
    7,089
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: DOS Variables (Windows XP)

    Tim - thanks for pulling that up. I had completely forgotten about it even though I frequently use SET /a in my scripts!
    -Mark

  5. #5
    Star Lounger
    Join Date
    Nov 2002
    Location
    Port Talbot, Wales
    Posts
    71
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: DOS Variables (Windows XP)

    Cheers Tim, just what the doctor ordered! I wanted to write a batch file that extracts Unreal Tournament files from inside zip files and places them in the appropriate directory, for this i needed to know where the unreal tournament directory was, thanks to you i can now ask the user!

    Thanks Again
    Jamie

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •