Home > OS >  Simulate two user inputs to a batch file programmatically
Simulate two user inputs to a batch file programmatically

Time:04-14

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.

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

CodePudding user response:

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
  • Related