Automatically respond to input prompt in windows package

In the windows package, I want to run a program that asks the user for input:

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

How can I automatically pass the input "y" to the prompt to start the program, simply by clicking on the package?

+9
source share
3 answers

Do you want to:

 echo y | [Command] 

For example: echo y | program.exe

 "echo <answer> | <batch command>" 

Ex: The del / P command option asks for user confirmation before deleting the file. Therefore, if you use this option in your script package, this requires manual input. To avoid this entry manually, use the "echo Y | del / P" command in the batch script folder to respond to the prompt.

You can try this echo command to pass the input (for example: response for username and password) to the console application when it is called through a batch script package.

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

+15
source

For multiple inputs, do:

(echo input1 && echo input2) | program.exe

+3
source

You can automate the user input prompt using VBScript, and then write a command to run VBScript in a batch script.

 Set WshShell = WScript.CreateObject("WScript.Shell") WshShell.Run "command_that_asks_for prompt", 9 WScript.Sleep 500 'Msg is first prompt answer Dim Msg: Msg = WshShell.ExpandEnvironmentStrings( "%DB_TYPE%" ) 'send character by character using for loop for first input prompt For i = 1 To Len(Msg) WScript.Sleep 200 WshShell.SendKeys Mid(Msg, i, 1) Next WshShell.SendKeys "{ENTER}" 'Msg2 is second input prompt answer Msg2 = WshShell.ExpandEnvironmentStrings( "%CONNECTION_TYPE%" ) ' send character by character for second input prompt For i = 1 To Len(Msg2) WScript.Sleep 200 WshShell.SendKeys Mid(Msg2, i, 1) Next WshShell.SendKeys "{ENTER}" 

The above code is an example to provide an answer to 2 user inputs. Similarly, we can provide a few tips. The above code can be saved as filename.vbs, and then write the command in VBScript in a batch script.

For instance:

 @echo off 'command to run VBScript filename.vbs pause 

This can be used as a batch script to automatically respond to input requests.

0
source

Source: https://habr.com/ru/post/1259768/


All Articles