我正在编写自己的简单系统,允许我在将 APK 上传到 GPlay 之前自动对其进行签名。我有一个执行签名的批处理文件;和一个“包装器”批处理文件,其内容将由 Jenkins 后期构建在命令行上运行。

sign_apks.bat:

@echo off

set /p job= "Enter job name: "
set /p alias= "Enter key alias: "
set /p mobile= "Sign mobile? (y/n): "
set /p wear= "Sign wear? (y/n): "

echo.
echo "%job%"
echo "%alias%"
echo "%mobile%"
echo "%wear%"

[the rest of the code is sensitive so is emitted, but these variables are used later]

包装代码:
@echo off

(echo test
echo test
echo y
echo y)| call sign_apks.bat

This article 向我展示了如何将值通过管道传输到程序中。引用答案,:
Multiple lines can be entered like so:

(echo y
echo n) | executable.exe

...which will pass first 'y' then 'n'.

但是,这不起作用。这是我运行包装器代码时得到的输出:
Enter job name: Enter key alias: Sign mobile? (y/n): Sign wear? (y/n):
"test "
""
""
""

帮助?

最佳答案

您知道,最简单的解决方案是提供 jobaliasmobilewear 作为脚本参数,而不是尝试将它们通过管道输入标准输入。如果您希望在没有参数的情况下以交互方式运行,您仍然可以 set /p 如果未定义。

@echo off
setlocal

set "job=%~1"
set "alias=%~2"
set "mobile=%~3"
set "wear=%~4"

if not defined job set /p "job=Enter job name: "
if not defined alias set /p "alias=Enter key alias: "
if not defined mobile set /p "mobile=Sign mobile? (y/n): "
if not defined wear set /p "wear=Sign wear? (y/n): "

echo.
echo "%job%"
echo "%alias%"
echo "%mobile%"
echo "%wear%"

然后当你 call sign_apks.bat 时,就这样称呼它:
call sign_apks.bat test test y y

关于batch-file - 在批处理脚本中将多个值通过管道传输到程序中,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27622474/

10-15 08:16