Windows 在shell脚本中执行的批处理文件不等待用户输入
我偶然发现了git钩子,并一直试图创建一个在Windows上运行的钩子。所以我决定使用批处理文件来实现这一点,因为它看起来很简单 首先,我将pre-commit示例重命名为pre-commit,并在那里调用了我的bat步骤:Windows 在shell脚本中执行的批处理文件不等待用户输入,windows,shell,batch-file,githooks,Windows,Shell,Batch File,Githooks,我偶然发现了git钩子,并一直试图创建一个在Windows上运行的钩子。所以我决定使用批处理文件来实现这一点,因为它看起来很简单 首先,我将pre-commit示例重命名为pre-commit,并在那里调用了我的bat步骤: #/垃圾箱/垃圾箱 $(pwd)/git hooks/hooks/unit_test.bat&& $(pwd)/git hooks/hooks/integration_test.bat unit_test.bat只显示一些消息并运行单元测试任务,但是integration
#/垃圾箱/垃圾箱
$(pwd)/git hooks/hooks/unit_test.bat&&
$(pwd)/git hooks/hooks/integration_test.bat
unit_test.bat只显示一些消息并运行单元测试任务,但是integration_test.bat会提示用户是否要运行这些测试,因为它们通常比较慢
问题在于提示(通过“选择”或“设置/p”完成)没有获得用户输入:
- “设置/p”不等待用户输入
- “选择”冻结,不允许任何用户输入
- 单位测试
- 集成测试
gradlew
实际上是另一个批处理文件,gradlew.bat
,因此我假设,如果希望它在完成后返回脚本,应该使用调用
命令。另外,您应该知道,&
在一行上连接两个单独的命令,而&
仅在前一个命令成功时运行一个命令。在您的情况下,Echo
命令不能不成功,因此只需&
。此外,If ErrorLevel 1
菜单中的错误代码为1
或更高,这意味着,在您发布的代码中,代码将始终转到sim卡
。您应该改为使用如果不是ErrorLevel 2
,如果%ErrorLevel%eq 1
,或者如果“%ErrorLevel%”==“1”
示例:(请插入gradlew.bat
的完整路径,而不是依赖容易损坏或受影响的%path%
变量,如果路径和可执行文件名包含空格或有问题的字符,请将其双引号引到)。我已经删除了下面示例中不必要的连接,因为脚本中不需要它
单元测试。bat
@Echo关闭
Echo^>unitários睾丸
调用gradlew.bat testReport | |(Echo(&Echo Testes unitários falharam!Acesse o relatório de Testes para confereir.&Exit 1)
集成测试.bat
@Echo关闭
回音(
Echo^>集成睾丸
%SystemRoot%\System32\choice.exe/C sn/M“Esses testes geralmente são mais lentos.Quer rodar os testes Integratedos”
如果不是错误级别2转到sim卡
回音(
Echo Não se esqueça de confirmar que os testes integrados passam antes de fazer o‘git push’!
退出/B
:sim卡
调用gradlew.bat集成测试| |(
回音(
Echo Testes integrados falharam!Acesse o relatório de Testes para confereir。
)
出口1
或:
@Echo关闭
回音(
Echo^>集成睾丸
%SystemRoot%\System32\choice.exe/C sn/M“Esses testes geralmente são mais lentos.Quer rodar os testes Integratedos”
如果错误级别2转到nao
调用gradlew.bat集成测试| |(
回音(
Echo Testes integrados falharam!Acesse o relatório de Testes para confereir。
)
出口1
:nao
回音(
Echo Não se esqueça de confirmar que os testes integrados passam antes de fazer o‘git push’!
退出/B
根据您正在使用的一些字符,我还建议您确保使用适当的代码页(可能是1252)运行脚本ommand仅在上一次成功时执行。在您的情况下,
Echo
命令不能失败,因此只需&
即可。此外,如果ErrorLevel 1
菜单中的错误代码为1
或更高,这意味着在您发布的代码中,代码将始终转到sim卡
。您应该告诉我们什么如果不是ErrorLevel 2,则e为,如果%ErrorLevel%Equ 1,则e为,如果“%ErrorLevel%”=1,则e为
示例:(请插入gradlew.bat
的完整路径,而不是依赖容易损坏或受影响的%path%
变量,如果路径和可执行文件名包含空格或有问题的字符,请将其双引号引到).我已经删除了下面示例中不必要的连接,因为脚本中不需要它
单元测试。bat
@Echo关闭
Echo^>unitários睾丸
调用gradlew.bat testReport | |(Echo(&Echo Testes unitários falharam!Acesse o relatório de Testes para confereir.&Exit 1)
集成测试.bat
@Echo关闭
回音(
Echo^>集成睾丸
%SystemRoot%\System32\choice.exe/C sn/M“Esses testes geralmente são mais lentos.Quer rodar os testes Integratedos”
如果不是错误级别2转到sim卡
回音(
Echo Não se esqueça de confirmar que os testes integrados passam antes de fazer o‘git push’!
退出/B
:sim卡
调用gradlew.bat集成测试| |(
回音(
Echo Testes integrados falharam!Acesse o relatório de Testes para confereir。
)
出口1
或:
@Echo关闭
回音(
Echo^>集成睾丸
%SystemRoot%\System32\choice.exe/C sn/M“Esses testes geralmente são mais lentos.Quer rodar os testes Integratedos”
如果错误级别2转到nao
调用gradlew.bat集成测试| |(
回音(
Echo Testes integrados falharam!Acesse o relatório de Testes para confereir。
)
出口1
:nao
回音(
Echo Não se esqueça de confirmar que os testes integrados passam antes de fazer o‘git push’!
退出/B
我还想买一辆自行车
@echo off
echo ^> Testes unitários
call gradlew testReport || (echo(& echo Testes unitários falharam! Acesse o relatório de testes para conferir.& exit 1))
@echo off
echo(echo ^> Testes integrados
%SystemRoot%\System32\choice.exe /C sn /M "Esses testes geralmente são mais lentos. Quer rodar os testes integrados"
if ERRORLEVEL 2 goto nao
call gradlew integrationTests || (echo(echo Testes integrados falharam! Acesse o relatório de testes para conferir.) && exit 1)
:nao
echo(echo Não se esqueça de confirmar que os testes integrados passam antes de fazer o 'git push'!)
exit /B