Democratic Underground Latest Greatest Lobby Journals Search Options Help Login
Google

How do I get a batch file in XP to accept keyboard input

Printer-friendly format Printer-friendly format
Printer-friendly format Email this thread to a friend
Printer-friendly format Bookmark this thread
This topic is archived.
Home » Discuss » DU Groups » Computers & Internet » Computer Help and Support Group Donate to DU
 
JohnyCanuck Donating Member (1000+ posts) Send PM | Profile | Ignore Sun Jan-23-05 10:53 PM
Original message
How do I get a batch file in XP to accept keyboard input
Edited on Sun Jan-23-05 11:02 PM by JohnyCanuck
I have XP home edition and I am experimenting with batch files by trying to put together a batch file to automate backing up the My Documents folder to a 2nd hard drive. I've got the backup part working OK using XCOPY etc., but now I am trying to gussy it up with some prompts etc. and I can't figure out how to get the batch file to recognize input from the keyboard.

Going by some examples I found on the internet, I thought I could use the CHOICE command to accept user input along the lines of the the example below.

ECHO This batch file backs up your My Documents folder
ECHO and your Outlook Express folder to the F drive.
ECHO.
ECHO Do you want to run the backup at this time?
ECHO.
CHOICE /C:YN /N Select Y for Yes or N for No
IF errorlevel 2 goto End
IF errorlevel 1 goto Run_Backup


When I try to run the above, I get an error message saying CHOICE is not recognized as an internal or external command. I assume there must be some way to get input from the keyboard in XP. Does anyone have any ideas?

Thanks
Printer Friendly | Permalink |  | Top
jayfish Donating Member (1000+ posts) Send PM | Profile | Ignore Sun Jan-23-05 11:15 PM
Response to Original message
1. I Think You Can Grab A Copy Of choice.com
from an MS-DOS install disk. You will have to decompress it using expand.exe. It should reside in your .\WINNT\System or .\Windows\System directory. Give it a shot.

Jay

Printer Friendly | Permalink |  | Top
 
welshTerrier2 Donating Member (1000+ posts) Send PM | Profile | Ignore Sun Jan-23-05 11:17 PM
Response to Original message
2. choice is DEAD in XP ... use the "set" command
it looks like it's been replaced with the "set" command ... here's an example:

source: http://www.computerhope.com/sethlp.htm#04

How to use the set command as a substitute for the choice command in Windows 2000 and Windows XP

In the below example a user would be prompted to enter an option of 1,2, or 3 to print "hello", "bye", or "test".

@ECHO off
cls
:start
ECHO.
ECHO 1. Print Hello
ECHO 2. Print Bye
ECHO 3. Print Test
set choice=
set /p choice=Type the number to print text.
if not '%choice%'=='' set choice=%choice:~0,1%
if '%choice%'=='1' goto hello
if '%choice%'=='2' goto bye
if '%choice%'=='3' goto test
ECHO "%choice%" is not valid please try again
ECHO.
goto start
:hello
ECHO HELLO
goto end
:bye
ECHO BYE
goto end
:test
ECHO TEST
goto end
:end
Printer Friendly | Permalink |  | Top
 
JohnyCanuck Donating Member (1000+ posts) Send PM | Profile | Ignore Mon Jan-24-05 02:12 AM
Response to Original message
3. Yup the set command does the trick.
Thanks for the feedback jayfish and WelshTerrier2
Printer Friendly | Permalink |  | Top
 
DU AdBot (1000+ posts) Click to send private message to this author Click to view 
this author's profile Click to add 
this author to your buddy list Click to add 
this author to your Ignore list Wed Apr 24th 2024, 07:39 AM
Response to Original message
Advertisements [?]
 Top

Home » Discuss » DU Groups » Computers & Internet » Computer Help and Support Group Donate to DU

Powered by DCForum+ Version 1.1 Copyright 1997-2002 DCScripts.com
Software has been extensively modified by the DU administrators


Important Notices: By participating on this discussion board, visitors agree to abide by the rules outlined on our Rules page. Messages posted on the Democratic Underground Discussion Forums are the opinions of the individuals who post them, and do not necessarily represent the opinions of Democratic Underground, LLC.

Home  |  Discussion Forums  |  Journals |  Store  |  Donate

About DU  |  Contact Us  |  Privacy Policy

Got a message for Democratic Underground? Click here to send us a message.

© 2001 - 2011 Democratic Underground, LLC