| 1. |
Solve : "delayed environment variable expansion" & "setlocal"? |
|
Answer» Recently Dark Blade posted a very interesting batch file USING the "set /p num= "......" command How does "delayed environment variable expansion" & "setlocal" tie in with the set/p command.Delayed expansion wouldn't have anything to do with the set /p unless the set /p was used inside of a FOR loop. The SETLOCAL command doesn't have much to do with set /p either except it would clean up / reset the variable(s) after the script has finished executing. I think your main question is how set /p works and what it does? The /P is basically a way for a batch script to Prompt a user for input. Without any parameters the SET command will simply assign a value t a variable. With SET /P the SET command will ask the user to input some text and then assign that entered text as the value for the variable. Example: Set the environment variable NAME: Code: [Select]set Name=llmeyer echo Name is %Name%Here the variable Name is hard coded with llmeyer Or for an interactive script you can do: Code: [Select]set /p Name=Enter your name: echo Name is %Name% In both of these cases, the environment variable "Name" would be set when the script was finished. To see what effect SETLOCAL has on the script, you can use Code: [Select]setlocal set /p Name=Enter your name: echo Name is %Name%When the script was finished the environment variable of "Name" would have the same value as before you ran the script, or if it was null / not set (which it probably would be unless you had something that already set it) then it would be null again at the end of the script. Is that what you were LOOKING for?Thank you both for your help. I am at work right now and can't check out the code from the batch file right now. If I had to guess, I strongly suspect that one of my mistakes was including spaces. I'll try to go back over my test file and sort it out, using the information and suggestions you provided. I'll let you know in the next couple of days how it works out. Thanks again.If you are still having problems, post your code so we can help you see where the problem is.I really do appreciate your help. I haven't had time to even look at the batch file I was working on. It may be a few days, but I have copied the text from the thread and will get back to it. I will try to work it out myself, with the help already provided, but if I get too bogged down, I will be back with the problem code. If I get it sorted out, I'll let you know also. Thanks again!Hey Guys, I finally got back to the set /p = ... problem I was having, and Dias de VERANO, you were right on with the "no spaces between the value name & the equals sign" suggestion. Thanks!!! I wasted quite a bit of time on that one. GuruGary, thanks for clarifying the "delayed environment variable expansion" & "setlocal" usages for me. I am so far behind the times. Back in 1995, I learned the CHOICE - IF ERRORLEVEL method in DOS 6.22 batch file programming. Now, in Windows XP, it seems choice is gone, with the set /p apparently filling the void. From reading a number of other threads, I can see that set/p is very powerful, but I can't understand Microsoft's logic in dropping the choice command? What if I want to write a batch file that is backward compatible, from Vista to Win 98??? Thanks again!Quote from: llmeyer1000 on March 03, 2008, 08:11:48 AM
Me too. Quote ... What if I want to write a batch file that is backward compatible, from Vista to Win 98??? Visit: http://hp.vector.co.jp/authors/VA007219/dkclonesup/choice.html Lots to read there. You can download an executable there that will run under XP. Can't remember if it is choice.exe there, or choice.com. Maybe both are there. No matter... you can grab it, and put it in a dir in your path. |
|