Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Batch files

Status
Not open for further replies.
Jun 2, 2003
24
US
What's the syntax to allow a batch file to answer a prompt automatically. For example: when asked " Are you sure? y/n"

thx.
 
I'm not sure if there is a simpler way to do it, but this is how I've always handled it...

Create a text file containing your answers. One answer per line.

If all you need is one response ( either y or n ) then your text file will only have one line containing the letter y or n. If you need two responses, the first one y and the second n, you will have two lines in your text file. The letter y on the first line and the letter n on the second.

When executing or calling the batch file, use redirection to feed your responses to it.

Example: test.bat < response.txt

This will work for .com and .exe commands as well.

The only possible drawback to this method is that once your command or batchfile receives a response this way, it will no longer take responses from the command line. You will have to include all responses in the text file in the order in which you expect them to be required. This may require considerable testing for complicated batch files.
 
Try an easy way using a pipe command

ie

Echo Y|pause

 
If you are copying and overwriting files etc simply use:

copy <FILE> to <LOCATION> /y (/y for yes)
 
Maybe if you posted exactly what it is you want a 'Yes' for?

Marc
[sub]If 'something' 'somewhere' gives 'some' error, expect random guesses or no replies at all. Please specify details.
Free Tip: The F1 Key does NOT destroy your PC!
[/sub]
 
hmmm..if its as simple as:

e.g.Overwrite C:\test\dbimport.txt (Yes/No/All)?

just put a /Y at the end of your batch file line.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top