Thursday, October 15, 2009

How to auto answer prompts in Windows batch script

To auto answer prompts in Windows batch script, try the following command.

"echo <answer> | <batch command>"

Ex: The del /P command option will prompt for user's confirmation before deleting the file.
So if you are using this option in your batch script, it requires manual input to proceed further.
To avoid this manual input, use the command "echo Y | del /P " in your batch script to answer the prompt.

You can try this echo command to pass input (ex: answer for username and password prompts) to your console application, when it is invoked through batch script.

9 comments:

  1. Your website is really cool and this is a great inspiring article. Thank you so much.
    see this

    ReplyDelete
  2. Please let me know, How to give multiple input.

    ReplyDelete
    Replies
    1. (echo input1 && echo input2) | your command

      Delete
    2. if we need inputs to be command specific.
      lets say if the command says "add first number" then it should echo "1" and if it asks for "add second number" then it should echo "2"

      Delete
    3. (echo input1 if "add first number" or echo input2 if "add second number") | your command

      Delete
  3. Same here... How DO i answer the userid/password you mentioned?

    ReplyDelete
  4. I am getting space character after myminput in password field hence its not verifying. What to do?

    ReplyDelete
  5. The writer has outdone himself this time. It is not at all enough; the website is also utmost perfect. I will never forget to visit your site again and again. salesflow.io

    ReplyDelete