Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Simulate two user inputs to a batch file programmatically

I have a batch file which requires 2 user inputs.

@echo Off
setlocal

echo.
echo Please select an opt:
echo.
echo 1
echo 2
echo.
set /p opt= Variant Number (1-2)?
echo.
echo opt selected is %opt%"

echo Please Select opt2:
echo.
echo 4
echo 5
echo.
set /p opt2= Variant Number (4-5)?
echo.
echo opt selected is %opt2%
goto end

:end
pause
endlocal

I want to invoke this batch file from a C# program and input 1 and 5 programmatically.

I tried (echo 1&&echo 5)|test.bat. But it is not working, giving output as blank for the 4-5 selection. This is working fine if there is only one input like echo 1|test.bat.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

This batch file is fixed and I don’t have rights to modify it. So method to simulate the user input is expected.

>Solution :

Create a text file with the desired values. Put each on their own line and be sure to press the Enter key after each value. Then your command line will be, for example:

test.bat < values.txt
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading