Dw2k Posted September 21, 2003 Share Posted September 21, 2003 Is it possible to make the batch file ask for user input?reason I ask is that I would like to copy certain files from my D: to my C: during the batch run but i'd like it to ask me if i'd want to or not and not bother coyping them?Thanks guys, great website you got here! Link to comment Share on other sites More sharing options...
KonuS Posted September 21, 2003 Share Posted September 21, 2003 @ECHO OFFSET MyInput=IF NOT '%1'=='' GOTO ReadySET /P MyInput=Enter filename:copy %myinput% c:\This will help? Link to comment Share on other sites More sharing options...
b0r3d Posted September 22, 2003 Share Posted September 22, 2003 User input can be done thusly:@Echo OffEcho Press 1 if you want to copy filesEcho Press 2 if you do not want to copy filesEcho Please make your selection...After throwing that code in a batch file (notice it doesnt actually do anything besides display text, but ill get to that in a minute), create 2 more batch files. one named "1.cmd" and the other "2.cmd".In "1.cmd" you place all the files you want to copy, and in "2.cmd" you pick up the setup where you left off.Explanation:In the code above, all it does is print text and displays it to the user. When its done, it brings it back to the command prompt at the directory where the batchfile was run. In this directory is where you place 1.cmd and 2.cmd. When the user presses 1 or 2, it executes the appropriate batch file. Simple!You can ofcourse change the names of the 1.cmd and 2.cmd, except you'll need to prompt the user to type in the filename of the command file, rather then just 1 or 2.Hope this helps! Link to comment Share on other sites More sharing options...
edg21 Posted September 22, 2003 Share Posted September 22, 2003 The following batch file snippet displays a simple menu (without a question-mark at the end of the prompt) and prompts for the users choice, defaulting to option 2 after 5 seconds :@ECHO OFFECHO 1. MS-DOS Editor.ECHO 2. MS-Windows. (default)ECHO 3. Defrag the hard-drive.ECHO 4. Quit.CHOICE /C:1234 /N /T:2,5 Please choose a menu option.IF ERRORLEVEL == 4 GOTO QUIT_MENUIF ERRORLEVEL == 3 GOTO DEFRAG_HDIF ERRORLEVEL == 2 GOTO RUN_WINIF ERRORLEVEL == 1 GOTO RUN_EDIT:RUN_EDITCALL EDIT:RUN_WINCALL WIN:DEFRAG_HDDEFRAG c::QUIT_MENUcredit: http://www.cs.ntu.edu.au/homepages/bea/hom...escription.html Link to comment Share on other sites More sharing options...
b0r3d Posted September 22, 2003 Share Posted September 22, 2003 Unfortunatly, the Choice command doesnt not work in Windows XP Link to comment Share on other sites More sharing options...
KonuS Posted September 22, 2003 Share Posted September 22, 2003 Unfortunatly, the Choice command doesnt not work in Windows XP@ECHO OFFSET MyInput=IF NOT '%1'=='' GOTO QUIT_MENUECHO 1. MS-DOS Editor.ECHO 2. MS-Windows.ECHO 3. Defrag the hard-drive.ECHO 4. Quit.SET /P MyInput=Please choose a menu option:IF %MyInput% == 4 GOTO QUIT_MENUIF %MyInput% == 3 GOTO DEFRAG_HDIF %MyInput% == 2 GOTO RUN_WINIF %MyInput% == 1 GOTO RUN_EDIT:RUN_EDITCALL EDIT:RUN_WINCALL WIN:DEFRAG_HDDEFRAG c::QUIT_MENUThis will work. Link to comment Share on other sites More sharing options...
Dw2k Posted September 22, 2003 Author Share Posted September 22, 2003 Thank you b0r3d! That works a treat. Much appreciated Link to comment Share on other sites More sharing options...
b0r3d Posted September 22, 2003 Share Posted September 22, 2003 No problammo. Glad i could help Link to comment Share on other sites More sharing options...
Sunil Posted September 22, 2003 Share Posted September 22, 2003 Unfortunatly, the Choice command doesnt not work in Windows XP@ECHO OFFSET MyInput=IF NOT '%1'=='' GOTO QUIT_MENUECHO 1. MS-DOS Editor.ECHO 2. MS-Windows.ECHO 3. Defrag the hard-drive.ECHO 4. Quit.SET /P MyInput=Please choose a menu option:IF %MyInput% == 4 GOTO QUIT_MENUIF %MyInput% == 3 GOTO DEFRAG_HDIF %MyInput% == 2 GOTO RUN_WINIF %MyInput% == 1 GOTO RUN_EDIT:RUN_EDITCALL EDIT:RUN_WINCALL WIN:DEFRAG_HDDEFRAG c::QUIT_MENUThis will work. This code works but unfortunatly when you finish using option 1,2 or three it automatically runs on the the next option, this is a revised one which automatically goes back to the menu when finished..@ECHO OFF:STARTSET MyInput=IF NOT '%1'=='' GOTO QUIT_MENUECHO 1. MS-DOS Editor.ECHO 2. MS-Windows.ECHO 3. Defrag the hard-drive.ECHO 4. Quit.SET /P MyInput=Please choose a menu option:IF %MyInput% == 4 GOTO QUIT_MENUIF %MyInput% == 3 GOTO DEFRAG_HDIF %MyInput% == 2 GOTO RUN_WINIF %MyInput% == 1 GOTO RUN_EDIT:RUN_EDITCALL EDITGOTO START:RUN_WINCALL WINGOTO START:DEFRAG_HDDEFRAG c:GOTO START:QUIT_MENU Link to comment Share on other sites More sharing options...
Dw2k Posted September 22, 2003 Author Share Posted September 22, 2003 Ahh thanks mate, both are good suggestions, and I thank you both Link to comment Share on other sites More sharing options...
kenneth11zz Posted September 23, 2003 Share Posted September 23, 2003 Hey guys, thanks for the quick tutorial on the batch commands. This is very helpful indeed. How would like someone write the code where the user picks up a menu choice and after it is done with that choice, it automatically continues on the installation without going back to the menu? For example, if I wanted to create this menu.1. Install Windows XP with original default.2. Install Windows XP (Tweaks Only)3. Install Windows XP (Tweaks and Themes)etc..Also, is there a way to log the output of display in a batch file? The line below the the CALL statement, is that a regular command file (filename.cmd)? I'm to all this stuff.-Kenneth Link to comment Share on other sites More sharing options...
demlak Posted September 24, 2003 Share Posted September 24, 2003 take a look at CD-Shellit´s more complicated.. but will do a much more comfortable menu at boot time.also it allowes much more to load, than just windows setup settings..in combination with the manual given on this site or this site u will get a very handy cd.. Link to comment Share on other sites More sharing options...
Dw2k Posted September 24, 2003 Author Share Posted September 24, 2003 Is there a way to dump the whole batch file into a .txt after it has executed? As its quite hard to spot errors as things install too quickly Link to comment Share on other sites More sharing options...
demlak Posted September 24, 2003 Share Posted September 24, 2003 start another batch file and call your batch file with output to txt file like this:call yourbatch.cmd > log.txt Link to comment Share on other sites More sharing options...
kenneth11zz Posted September 25, 2003 Share Posted September 25, 2003 Thanks demlak for the tip. I'll check it out.-Kenneth Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now