Solved

user input for batch file

Posted on 2000-02-25
10
699 Views
Last Modified: 2013-12-28
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.
0
Comment
Question by:kuriti_mohan
  • 2
  • 2
  • 2
  • +4
10 Comments
 
LVL 23

Expert Comment

by:Tim Holman
Comment Utility
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
 

Author Comment

by:kuriti_mohan
Comment Utility
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
 
LVL 10

Expert Comment

by:tonnybrandt
Comment Utility
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
 
LVL 4

Expert Comment

by:adam923
Comment Utility
if you just want to capture one keystroke you can use choice (run help choice from nt command prompt for more info)
0
 
LVL 1

Expert Comment

by:vishone
Comment Utility

 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
Want to promote your upcoming event?

Attending an event? Speaking at a conference? Or exhibiting at a tradeshow? Easily inform your contacts by using a promotional banner in your email signature. This will ensure your organization’s most important contacts are in the know.

 
LVL 4

Expert Comment

by:adam923
Comment Utility
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
 
LVL 1

Expert Comment

by:vishone
Comment Utility


 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
 

Author Comment

by:kuriti_mohan
Comment Utility
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
 
LVL 1

Expert Comment

by:ronaldvr
Comment Utility
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
 

Accepted Solution

by:
csabay earned 100 total points
Comment Utility
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

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

A few months ago I had an issue with LaserJet 1020 printer which was installed to XP and Windows 7.  It was installed to XP and working, but when I tried to connect from a Windows 7 PC, it would attempt connection and then fail.  Sometimes the Spool…
NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…

762 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

12 Experts available now in Live!

Get 1:1 Help Now