Kube Posted July 25, 2009 Share Posted July 25, 2009 Well, Im quite a novice to the MS-DOS and know most basics on it but I can't find anywhere that explains how to do this,Basically what I want to do is have the %USER% input a Name, Then the output would be %NAME%For example,I've used,:4@echo Good, What's your name?:5 set /p Hello="Type Your Name - "if "%Hello%"=="Bob" goto :6@echo Invalid command!goto :5If you don't understand please reply and i'll go into more detail. Link to comment Share on other sites More sharing options...
jaclaz Posted July 25, 2009 Share Posted July 25, 2009 (edited) SET /P does not exist in MS-DOS.It exists in NT based systems, starting with Windows 2000.In MS-DOS you had choice.com or one of the various replacements for it:http://ss64.com/nt/choice.htmlWhere would you put the "ELSE" statement? Check this:http://ss64.com/nt/set.htmlhttp://ss64.com/nt/if.htmlSee this also:http://ss64.com/nt/syntax-conditional.htmlRead on this site:http://www.robvanderwoude.com/http://www.robvanderwoude.com/batchstart.phphttp://www.robvanderwoude.com/userinput.phpjaclaz Edited July 25, 2009 by jaclaz Link to comment Share on other sites More sharing options...
CoffeeFiend Posted July 25, 2009 Share Posted July 25, 2009 I was thinking he meant "command prompt" instead of MS-DOS (whereas batch files would have been more appropriate anyways)I mean, what's the odds he's using a pre-Win95 OS that's 15 years old or more? Link to comment Share on other sites More sharing options...
dencorso Posted July 25, 2009 Share Posted July 25, 2009 Hi, Kube!Your code is sound, for a NT-family OS DOS Box, however the if statement ought to be without the inverted double commas, like this:@echo off(...):4echo Good, What's your name?:5 set /p Hello="Type Your Name - "if %Hello%==Bob goto :6if %Hello%==Kim goto :7if %Hello%==John goto :8if %Hello%==Gwen goto :9echo Invalid command!goto :5:6:7:8:9echo Hi,%Hello%!(...)The last two commands in the code snippet do function as the ELSE you're looking for. So, you've alredy found a working solution. In any case, the input will be case sensitive, so that Bob will goto :6, but bOb, BOB, etc, will not.And if you use @echo off on the first line, you don't need to add @ to the other echo commands. Link to comment Share on other sites More sharing options...
jaclaz Posted July 25, 2009 Share Posted July 25, 2009 (edited) With all due respect to dencorso something like this seems to me a bit more "modern" (and readable) :@ECHO OFFSET USERS= Bob Kim John Gwen:loopECHO Good, What's your name?SET /P Hello=Type Your Name - FOR %%A in (%users%) DO (IF /I %%A.==%Hello%. GOTO :user_%Hello%) ELSE (ECHO User %%A Not Found!&GOTO :loop))GOTO :EOF:user_BobECHO So you are %Hello%, right? GOTO :EOF:user_KimECHO So you are %Hello%, right? GOTO :EOF:user_JohnECHO So you are %Hello%, right? GOTO :EOF:user_GwenECHO So you are %Hello%, right? GOTO :EOFjaclaz Edited July 25, 2009 by jaclaz Link to comment Share on other sites More sharing options...
Kube Posted July 25, 2009 Author Share Posted July 25, 2009 Thanks for all your help, and so fast aswell.So if im correctset /p Hello="Type Your Name - "if %Hello%==Bob goto :6if %Hello%==Kim goto :7if %Hello%==John goto :8if %Hello%==Gwen goto :9echo Invalid command!if %Hello%==Bob goto :# - Checks for the input to be Bob then if it is it will go to :#, However if it's not it will go to the second line and check for the name Kim and so on. Link to comment Share on other sites More sharing options...
dencorso Posted July 25, 2009 Share Posted July 25, 2009 @Kube:if %Hello%==Bob goto :# - Checks for the input to be Bob then if it is it will go to :#, However if it's not it will go to the second line and check for the name Kim and so on.Right! And only in case no one of the "if %Hello%==??? goto :#" comands are true then execution will reach the "echo Invallid command! and loop back because of the goto :5.@jaclaz: your solution *is* very elegant and beautiful. But, with all due respect to you, it sidesteps the precise question Kube had posed. I tried to cater for that specific question... Then again, I *do* like linear programming with lots of labels and GOTOs. Link to comment Share on other sites More sharing options...
Yzöwl Posted July 25, 2009 Share Posted July 25, 2009 I'm a little confused about what you mean by an Else statement, (as you can see one isn't required).:4Set/p "Hello=Good, What's your name? "If /i Not "%Hello%"=="Bob" (Echo Invalid Name!&Goto 4):5 Link to comment Share on other sites More sharing options...
Kube Posted July 25, 2009 Author Share Posted July 25, 2009 (edited) Thanks for all your help, I like the other one you posted ut it looks a bit too complicated for me at this time,Also one more little question, Is there any way to reference their input so that it outputs the word they input,For exampleIt'll ask you to type your name,But because I can't list every name possible I want it to reference the name and then output it,Would it be@echo off:nameset /p Hello="- "if %Hello%==%Hello% goto :1echo.echo.echo Invalid Commandecho.echo.goto :name:1echo Hello %Hello%!!!pauseI think that's correct, Edited July 25, 2009 by Kube Link to comment Share on other sites More sharing options...
Yzöwl Posted July 25, 2009 Share Posted July 25, 2009 Is there any way to reference their input so that it outputs the word they input,For exampleIt'll ask you to type your name,But because I can't list every name possible I want it to reference the name and then output itI'm afraid you're not making this easy, it appears that you have an idea of what you wish to achieve, but you're keeping it to yourself and asking for information in small increments so as not to disclose it to us!Tell us exactly what you are trying to do and perhaps give us the entire script and not just portions of it.What do you mean by reference their input?This will ask the question and output the non empty Name, if the Name is empty it will ask the question again. (It uses the Else statement as mentioned in your opening post).@Echo off&Setlocal enableextensions:AskNameCls(Set/p NameIs=What is your Name? )If Not "%NameIs%"=="" (Echo Hello %NameIs%!!!) Else (Goto AskName)Pause Link to comment Share on other sites More sharing options...
jaclaz Posted July 25, 2009 Share Posted July 25, 2009 if %Hello%==%Hello% goto :1I think that's correct,Well, if you can show me an example of a case where %Hello% will be different from %Hello%....http://en.wikipedia.org/wiki/Tautology_(logic)jaclaz Link to comment Share on other sites More sharing options...
Kube Posted July 25, 2009 Author Share Posted July 25, 2009 (edited) By reference the input is save it as a %Something%Here's the entire code, It's a bit nooby seeing as im just testing things and messing around,@echo offtitle Hello :Pcolor b:1echo Helloecho.echo.set /p Hello=""echo.echo.if %Hello%==Hello goto :2if %Hello%==Hi goto :2echo.echo.echo Incorrect commandecho.echo.goto :1:2echo.echo.echo Hi, How are you?echo.echo.:3set /p Hello=""if %Hello%==Fine goto :4if %Hello%==Good goto :4if %Hello%==Great goto :4if %Hello%==Cool goto :4if %Hello%==Bad goto :4if %Hello%==Cold goto :4if %Hello%==Hot goto :4if %Hello%==Weird goto :4if %Hello%==I dunno you tell me goto :4echo.echo.echo Feeling is not registered.echo.echo.goto :3:4echo.echo.echo Oh so you're feeling %Hello%? Just wondering what's your name? echo.echo.:5set /p Hello=""if %Hello%==%Hello% goto :6echo.echo.echo Invalid Name!!!echo.echo.goto :5:6title Hello %Hello%!echo.echo.echo Hi, %Hello%! My name is MS-DOS Command Promptecho.echo.pauseecho.echo.echo Bye %Hello%!echo.echo.pauseexitSorry about all the echo's and echo.'s that's just to space things out,So basically.It's going to ask you "What's your name?"Yet, I want it to register each name and then output it, but not output words like hello and jugga and frog, since they're not names, But I doubt that's possible. Edited July 25, 2009 by Kube Link to comment Share on other sites More sharing options...
CoffeeFiend Posted July 25, 2009 Share Posted July 25, 2009 I wouldn't even try to use batch files for this.Batch files are a very rudimentary "script" type that was designed 25+ years ago and improved very little since (added some basic things like FOR loops, and not much more)Batch files are still great for things like passing command line arguments to apps and the like (really simple tasks) but that's about it. Beyond that, there are better options.You could try using a simple scripting language (vbscript, jscript, autoit, etc -- powershell is great, but perhaps not very well suited to this particular task), or a "real" programming language -- there are several great options that are absolutely free like these. There's also guides to get you started and all that. Link to comment Share on other sites More sharing options...
Kube Posted July 25, 2009 Author Share Posted July 25, 2009 I wouldn't even try to use batch files for this.Batch files are a very rudimentary "script" type that was designed 25+ years ago and improved very little since (added some basic things like FOR loops, and not much more)Batch files are still great for things like passing command line arguments to apps and the like (really simple tasks) but that's about it. Beyond that, there are better options.You could try using a simple scripting language (vbscript, jscript, autoit, etc -- powershell is great, but perhaps not very well suited to this particular task), or a "real" programming language -- there are several great options that are absolutely free like these. There's also guides to get you started and all that.Okay thankyou, I also doubt it's possible with Batch anyways Im just seeing what's possible with batch and stuff, Thanks for all your help. Link to comment Share on other sites More sharing options...
Yzöwl Posted July 25, 2009 Share Posted July 25, 2009 You cannot possibly list every known feeling nevermind all real names!Is there a particular reason why you cannot output a list/index of responses to choose from instead of trying to achieve the impossible? Link to comment Share on other sites More sharing options...
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