Solved

Batch file that will accept text input

Posted on 2006-06-12
8
838 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
0
Comment
Question by:woodas26
8 Comments
 
LVL 13

Expert Comment

by:prashsax
ID: 16888619
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.

0
 
LVL 15

Expert Comment

by:Naser Gabaj
ID: 16888635
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:

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

Good Luck!

Naser
0
 
LVL 13

Expert Comment

by:prashsax
ID: 16888684
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.



0
 
LVL 95

Accepted Solution

by:
Lee W, MVP earned 500 total points
ID: 16888745
Under XP, 2000, NT, 2003, this is easy:

SET /p BarCode=Enter bar code:
Echo %barcode% >> C:\KCD\data.txt
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 13

Expert Comment

by:prashsax
ID: 16888793
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.
0
 
LVL 95

Expert Comment

by:Lee W, MVP
ID: 16888851
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.
0
 
LVL 13

Expert Comment

by:prashsax
ID: 16888888
Ok.

I was thinking something else.

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

0
 
LVL 4

Author Comment

by:woodas26
ID: 16888902
Exactly what I was looking for leew!  Thanks so much!
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Short answer to this question: there is no effective WiFi manager in iOS devices as seen in Windows WiFi or Macbook OSx WiFi management, but this article will try and provide some amicable solutions to better suite your needs.
If you're not part of the solution, you're part of the problem.   Tips on how to secure IoT devices, even the dumbest ones, so they can't be used as part of a DDoS botnet.  Use PRTG Network Monitor as one of the building blocks, to detect unusual…
Viewers will learn how to connect to a wireless network using the network security key. They will also learn how to access the IP address and DNS server for connections that must be done manually. After setting up a router, find the network security…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now