There is something very odd with how SET /P interacts with your piped input that I do not fully understand.
But I do have some solutions :-)
The simplest solution is to write your responses to a temporary file, and then use that temp file as redirected input.
@echo off
(
echo test
echo test
echo y
echo y
)>responses.temp
call sign_apks.bat <responses.temp
delete responses.temp
That is how I would solve your problem. But some people do not like to use temporary files (why I don't know). So I decided I would attempt to solve it using a pipe without a temp file.
I discovered an odd variation of your code that almost solves the problem - but it appends an extra unwanted space at the end of each value.
@echo off
(
call echo test1
call echo test2
call echo y1
call echo y2
) | sign_apks.bat
--OUTPUT--
Enter job name: Enter key alias: Sign mobile? (y/n): Sign wear? (y/n):
"test1 "
"test2 "
"y1 "
"y2 "
I cannot explain why the CALL enables each of the SET /P statements to work properly. But I can explain why the space is appended to each value. It has to do with why CALL is not needed when you use a batch script with a pipe.
Each side of a pipe is executed in a brand new cmd.exe session. For example, the right side of the pipe becomes a command that looks something like:
C:\Windows\system32\cmd.exe /S /D /c" sign_apks.bat"
This is the reason why CALL is not needed - control will return after the new cmd.exe session terminates.
The unwanted spaces are an artifact of how pipes process parenthesized blocks. The parser must capture the entire piped code block and transform it into a single line that can be incorporated into the CMD.EXE /C argument. The CMD.EXE parser does this by putting an & between each command. Unfortunately, the parser also inserts some extra spaces. So the left side of the pipe is transformed into something like:
C:\Windows\system32\cmd.exe /S /D /c" ( call echo test & call echo test & call echo y & call echo y )"
Now you can easily see where the unwanted trailing spaces are coming from. See Why does delayed expansion fail when inside a piped block of code? for more information about how pipes are implemented.
I finally came up with one more solution. I created a helper batch script called WriteArgs.bat that simply ECHOs each argument passed to it.
WriteArgs.bat
@echo off
:loop
if .%1 equ . exit /b
echo %1
shift /1
goto loop
With this simple batch script, you can now solve your problem using:
WriteArgs.bat test test y y | sign_apks.bat
Again, I don't understand why SET /P works properly here, yet doesn't work with your original command. But this does solve the problem :-)
Update - Well, it solves the problem on my machine. But it seems to be a timing issue, and I don't have confidence that any given piped solution will always work. The only solution I feel is robust is the one that uses a temp file and redirection.