场景:我有一个预提交的批处理脚本,该脚本检查空白注释,并调用vbscript文件来授权用户。然后,vbscript文件退出wscript.echo
1或wscript.echo 0
之后,控件返回到批处理文件以成功或失败退出。
@ECHO OFF
set REPOS=%1
set TXN_NAME=%2
set DEBUG=0
SET ThisScriptsDirectory=%~dp0
set svnlook = "C:\Program Files\TortoiseSVN\bin\"
REM: check for blank comment
for /f "tokens=*" %%a in ('%svnlook% svnlook author -t %TXN_NAME% %REPOS%') do set AUTH_NAME=%%a
%svnlook% svnlook log %REPOS% -t %TXN_NAME% | findstr .................... > nul
if %errorlevel% gtr 0 (goto err) else (goto noerr)
:err
echo. 1>&2
echo Your commit has been blocked because you didn't enter a comment. 1>&2
echo Write a log message describing the changes made and try again. 1>&2
echo Thanks 1>&2
exit 1
:noerr
for /f %%i in ('cscript.exe //nologo %ThisScriptsDirectory%pre-commiting.vbs %REPOS% %TXN_NAME% %ThisScriptsDirectory% %AUTH_NAME%') do set vars = %%i
if %vars% == "0" ( goto success) else (goto failure)
:failure
echo. 1>&2
echo You do not have the permissions to work on this repository. 1>&2
echo Request modifications access from support team. 1>&2
echo Thanks 1>&2
exit 1
:success
echo Commit Authorized...
exit 0
我尝试对我的vbscript执行回显到文件,并且似乎返回1或0,这正是我期望的结果。
提前致谢。。。
set
命令中的空格很重要,并且包含在变量的值和名称中。
....
.... set "vars=%%i"
if
仅当左右操作数遵循相同规则时,运算符才起作用。如果您引用一个值,请同时引用另一个。如果不是,则一个值将带有引号,另一个不带条件,并且条件将始终评估为false
if "%vars%"=="0"
if %vars%==0
if "%vars%" equ "0"
if %vars% equ 0
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句