user input for batch file

how can i take user input from the keyboard in dos like

"int a; printf("Enter a number:"\n); scnaf("%d",&a)" in c language.

I want to use this DOS comand in a batch file. reply me soon. Urgent.
kuriti_mohanAsked:
Who is Participating?
 
csabayConnect With a Mentor Commented:
Hi, kurti mohan,

look at the following batch file:

@echo Enter your number and a ^Z
@copy ee2.bat + con ee3.bat /b > NUL
@call ee3
@echo %number%

EE2.BAT is a special batch file with the contetnt as follows:

@set number=

Care shuld be taken when creating this batch file. No Carriage Return / Line Feed must be left at the end of the file. Use an editor which does not put these characters to there. E.g. you can use Far's or Norton Commander's F4 built in editor.

The batch works as follows:

prompts for the number
copies EE2.BAT and user input to a scratch name
calls for the actual form to have set the variable NUMBER
echoes the value of NUMBER for sake of control

After this point of the batch you can use the variable NUMBER to have control over your batch.

The one handicap of this solution is that requires the user put a ^Z after his/her input.

I'm sure this will help.

Charles
0
 
Tim HolmanCommented:
With MS DOS, you had to get Turbobat / Powerbatch to do this.
Under NT, there's no way, unless you compile this C program into a .COM and call the .COM to do the input for you.

http://gearbox.maem.umr.edu/~batch/awk.scripts.user.input1.html

is a helpful link.

It suggests GAWK, but again that's something you need to install on your system.
0
 
kuriti_mohanAuthor Commented:
sorry what i mean is i want to know the dos command which is similar to the c language example I gave. Thank U.
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
tonnybrandtCommented:
As Tim writes, there's no standard dos-command that can do what you wants. Since you obviosly know some C langauage, compile a utility yourself. You have almost written it already. That way you can be in control of errorchecking etc.
0
 
adam923Commented:
if you just want to capture one keystroke you can use choice (run help choice from nt command prompt for more info)
0
 
vishoneCommented:

 Hi kuriti_mohan,

    It is possible to prompt for the user input for the
    batch file. Probably you can use this method.

    For this,
    (1) Create a shortcut for the batch file.
    (2) In the properties window for the shortcut,
        Program tab, Command lIne field, enter a
        space and question mark after the command
       
       For example, the command line should look like
       <PATH><\BATCHFILENAME> ?
       
    (4) Now if you double click on this short cut, a
         small window appears to accept the parameters.

    You can refer the parameters inside the batch file
    in usual %1, %2 ... convention.

 - Vish
0
 
adam923Commented:
vishone:
i don't think this works in nt 4.0. there is no program tab on a shortcut and there is no command line field.  which version of windows are you talking about?
0
 
vishoneCommented:


 Hi adam923,

    The property window for "Short-cut to
    MS-DOs Program" will have "Program"
    tab. Note that this shortcut properties
    is different from other.


    The easiest way to create this type of
    short cut is to copy the "_DEFAULT" file
    that can be found in WINNT folder and
    change the command line field to point
    to the batch file.


    Check the properties for "_DEFAULT"
    file for the "Program" Tab


 - Vish
0
 
kuriti_mohanAuthor Commented:
All the parameters for the batch file can be given at the beginning of executing the batch file. So there is no way to give input while the batch file is running.
0
 
ronaldvrCommented:
You could try 4NT, a shareware product from JPSoft. This program enhances the CMD Batch language considerably.

Website

http://www.jpsoft.com/4ntdes.htm

An  alternative solution from the same guys is Take Command which is GUI oriented.

Ronald
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.