Automatically answer to input prompt in windows batch

后端 未结 3 662
小蘑菇
小蘑菇 2021-02-03 21:52

In a windows batch, I want to start a program that prompts the user for an input:

>someProgram.exe
> \"Please enter \"s\" to start the program:
> 
         


        
3条回答
  •  面向向阳花
    2021-02-03 22:16

    You want this:

    echo y | [Command]
    

    Eg: echo y | program.exe

    "echo  | "
    

    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.

    Refer: http://thirutechie.blogspot.com/2009/10/how-to-auto-answer-prompts-in-windows.html

提交回复
热议问题