Windows 查找在批处理脚本中运行时发生的位置或哪一行错误?

Windows 查找在批处理脚本中运行时发生的位置或哪一行错误?,windows,batch-file,syntax-error,error-logging,Windows,Batch File,Syntax Error,Error Logging,我想知道批处理脚本发生错误的错误行号,并且我想在批处理脚本中打印整行 set t=%date%_%time% set x=FORD_DLCM_T6_FTC set a="%m%\%x%" cd /d "C:\PRQA\PRQA-Framework-2.1.2\common\bin" qacli admin --set-license-server 5055@00.00.0.0 || goto :error qacli admin --debug-level DEBUG || goto :err

我想知道批处理脚本发生错误的错误行号,并且我想在批处理脚本中打印整行

set t=%date%_%time%
set x=FORD_DLCM_T6_FTC
set a="%m%\%x%"
cd  /d "C:\PRQA\PRQA-Framework-2.1.2\common\bin"
qacli admin --set-license-server 5055@00.00.0.0 || goto :error
qacli admin --debug-level DEBUG || goto :error
goto :EOF
:error
set remark= %ERRORLEVEL%
set status= Failure
echo ProjectName: %x%
echo Status: %status%
echo Remark: %remark%
echo Date: %t%
echo %x%,%status%,traceback(),%t% > "C:\Test\Build.csv"
echo Failed with error #%errorlevel%.
exit /b %errorlevel%

有人能帮我吗?

杰布描述了搜索右行的过程。在发生错误的情况下,将触发一个调用,参数是唯一的字符串和偏移量,它指向正确行的缺失行数。Findstr查找无误的字符串并打印该行号。与和解,这是正确的再次

我把一些宏放在一起,说明还有其他方法可以读取正确的行

@echo off
setlocal
set prompt=$g$s
call :setAllmacros
(call)
 rem begin in echo off - what line is it please ?
%ID-1:##==rem?% 
(call )
%ID-1:##==call%
set/a+
%ID-1:##==001% call :ErrorLogging Line:%%L Errorlevel:%errorlevel% 
echo 2

(call) || %ID-0:##==2% call :Errorlogging Line:%%L Errorlevel:%%errorlevel%% 
echo %errorlevel%
find /n  || %ID-0:##==003% call :Errorlogging Line:%%L Errorlevel:%%errorlevel%% 

%ID-0:##==008%
pushG 556
%ID-1:##==004% call :ErrorLogging Line:%%L Errorlevel:%errorlevel% 

%Line#print%:33=="

pause
exit /b

:errorlogging
@echo on
rem %*
@echo off
exit /b

:setAllmacros
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
(set ^"lf=^
%== define LF + CR ==%
)
for /f %%i in ('copy /z "%~f0" nul') do set "CR=%%i"

 rem Prints the fullline itself with LineNumber into stderr
 rem  usage: %Line#print%:UniqueID"
 rem   command || %Line#print%:01"
set "Line#print= @ <"%~f0" >&2 find /n "%%Line#print%%"

 rem Read the fullline BEFORE into Variables with LineNumber; do something ... 
 rem  usage: command 1 line before
 rem         %ID-1:##==01% [command %%L ... %%M ...]
set ID-1=  if errorlevel 1 for /f "usebackQtokens=1*delims=:" %%L in (^
 `cmd /v /c ^"findstr /n /r /c:"..*^!CR^!*^!LF^!.*ID-1:.#^=^##%%" "%~f0"^"`) do ^>^&2 echo BatchLine: %%L -- %%M ^& 

 rem Read the fullline itself into Variables with LineNumber; do something ... 
 rem  usage: command || %ID-0:##==01% [command %%L ... %%M ...]
set ID-0= @ for /f "tokens=1*delims=:" %%L in ('findstr /n /r /c:"ID-0:.#=##%%" "%~f0"') do ^>^&2 echo BatchLine: %%L -- %%M ^& 
exit /b
@echo关闭
setlocal
set prompt=$g$s
调用:setAllmacros
(电话)
rem从echo off开始-请问是哪一行?
%ID-1:##==rem?%
(电话)
%ID-1:##==呼叫%
一套+
%ID-1:##==001%调用:错误记录行:%%L错误级别:%Errorlevel%
回声2
(调用)| |%ID-0:##==2%调用:错误记录行:%%L错误级别:%%Errorlevel%%
回显%errorlevel%
查找/n | |%ID-0:##==003%调用:错误记录行:%%L错误级别:%%Errorlevel%%
%ID-0:##==008%
pushG 556
%ID-1:##==004%调用:错误记录行:%%L错误级别:%Errorlevel%
%行#打印%:33==”
暂停
退出/b
:错误记录
@呼应
雷姆%*
@回音
退出/b
:setAllmacros
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
(一套)=^
%==定义LF+CR==%
)
对于/f%%i in('copy/z“%~f0“nul'),请设置“CR=%%i”
rem将带有行号的整行打印到stderr中
rem使用率:%Line#print%:UniqueID“
rem命令| |%Line#print%:01“
设置“行打印=@&2查找/n”%%行打印%%
rem在使用LineNumber读取变量之前读取整行;执行某些操作。。。
rem用法:之前的命令行
rem%ID-1:##==01%[命令%%L…%%M…]
设置ID-1=如果/f“usebackQtokens=1*delims=:”%%L in的错误级别为1(^
`cmd/v/c^“findstr/n/r/c:…*^!CR^!*^!LF^!*ID-1:。#^=^##^%%“”%~f0 ^ ^ `)do^>^&2回显批处理行:%%L--%%M^&
rem将整行本身读入带有LineNumber的变量;执行某些操作。。。
rem用法:command | |%ID-0:##==01%[command%%L…%%M…]
set ID-0=@for/f“tokens=1*delims=:”%%L in('findstr/n/r/c:'ID-0:。#=#=#%%“”%~f0“')do^>^&2回显批处理行:%%L--%%M^&
退出/b
希望能有帮助


Phil

你在寻找这样的东西吗:是的,退出更苗条,但我期望的是…..我想得到错误发生的行号并分配给变量。你能帮我吗?你检查了接受的答案吗?错误行已经存储在变量中…我有点困惑,你能解释一下吗?@aschipfl