Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to userinput without typing to a batch file

Tags:

batch-file

cmd

I am trying to run a batch file which requires user input "y/n" to do further action. I want to call this batch file for automation, as during automation argument yes or no need to be passed without user intervention, any idea how to achieve it ?

cmd /c setup.bat

Now if setup.bat is run " yes or no " need to be selected to get the desired result as now this setup.bat is called during automation. Is there anyway to pass "yes" parameter as an input to setup.bat?

like image 238
Blood hound Avatar asked Dec 27 '22 18:12

Blood hound


2 Answers

You can use stream operators like <. Write every expected answer one per line in a file (e.g. foi). Pass this file to the setup.bat using < operator:

cmd /c setup.bat < foi
like image 79
lashgar Avatar answered Jan 13 '23 16:01

lashgar


Use below command line to automate "yes" answer by simulating y key press (will include the ENTER key).

cmd /c echo y^> "%temp%\answer.tmp" ^& (setup.bat ^< "%temp%\answer.tmp") ^& del "%temp%\answer.tmp"

To automate "no" answer by simulating n key then ENTER` key.

cmd /c echo n^> "%temp%\answer.tmp" ^& (setup.bat ^< "%temp%\answer.tmp") ^& del "%temp%\answer.tmp"

To automate "yes" answer by simulating "yes" key presses then ENTER key:

cmd /c echo yes^> "%temp%\answer.tmp" ^& (setup.bat ^< "%temp%\answer.tmp") ^& del "%temp%\answer.tmp"

To automate "no" answer by simulating "no" key presses then ENTER key:

cmd /c echo no^> "%temp%\answer.tmp" ^& (setup.bat ^< "%temp%\answer.tmp") ^& del "%temp%\answer.tmp"
like image 32
Jay Avatar answered Jan 13 '23 14:01

Jay