We help IT Professionals succeed at work.

Batch file that will accept text input

woodas26
woodas26 asked
on
952 Views
Last Modified: 2008-02-01
I'm trying to create a batch script that will accept input from a user.  The user needs to be able to key in a twelve digit UPC code, and that value should be appended to c:\KCD\data.txt.  The system is XP Pro.  Does anyone know the syntax to make the batch file wait for input, and then write the data entered to a .txt file when the user presses "Enter"?

TIA,
Andrew
Comment
Watch Question

Top Expert 2006

Commented:
You do not have any builtin tool for accepting Text as input.

But, their could exist some utility which can be used.

If you know some programming language, like QBASIC, you could write a program which would ask it from user and set it as environment variable.

Naser GabajE&P Senior Software Specialist
CERTIFIED EXPERT

Commented:
Greetings woodas26,

Although I'm not expert in Batching, but i remember there is a command "choice.exe" that can do the job for you, check this for more info:

https://www.experts-exchange.com/Operating_Systems/MSDOS/Q_20978849.html

Good Luck!

Naser
Top Expert 2006

Commented:
Choice will only accept one character from your given of choice.(e.g Y/N, 1,2,3 etc)

It will not accept text stream at runtime.



Technology and Business Process Advisor
CERTIFIED EXPERT
Most Valuable Expert 2013
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Top Expert 2006

Commented:
But, how would he take input from within the batch script is the question.

He could use %1 in place of "Enter Bar code:" at startup.

But he does not know this value.

User will have to fill it in once the script is started.

I assume it will be a startup script or logon script for user.

The, best option here is to use VBScript, take input in VBScript and call batch script from it.
Lee W, MVPTechnology and Business Process Advisor
CERTIFIED EXPERT
Most Valuable Expert 2013

Commented:
You're not using %1 - you are using the set command to prompt you for input - it waits until the input is entered.  Once it's entered, the input is stored in %barcode%.

Echo then displays the entered barcode.  >> c:\kcd\data.txt means append to the file c:\kcd\data.txt instead of displaying it on screen

It's two lines of easy code - much more efficient than a vbscript.
Top Expert 2006

Commented:
Ok.

I was thinking something else.

Yes, this is the best way and the solution as well.

Author

Commented:
Exactly what I was looking for leew!  Thanks so much!
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.