在我的批处理文件中,我有一个函数,使用此命令连接到远程主机:
net use %alias%: \\%host%\%root%$ %usrPwd% /USER:%usrName% >> %logfile% 2>&1 || ( call :exitIfError ERROR)
我创建了这个函数:
:exitIfError
setlocal
(set txt=%~1)
if not ERRORLEVEL 0 ( echo %txt% && exit /B %errorlevel%)
endlocal
goto :eof
如果输入的密码不正确,则会生成错误,但错误无法完成且%errolevel%的值为0 而不是2.建议?
答案 0 :(得分:0)
:exitIfError
if ERRORLEVEL 1 (echo %~1& exit /B %errorlevel%)
exit /b 0
似乎没有理由设置txt