下面的脚本片段有效吗?我想要的是,如果
:isRunning
返回非零,则运行 :startRunning
。
call :isRunning %parentCntr% || call :startRunning %parentCntr%
:isRunning
set ThreadNum=Thread=%1
rem set /p continue=in isRunning with ThreadNum set to %ThreadNum%
wmic process where "name like '_progres.exe' and commandline like '%%%tgtString%%%' and commandline like '%%%ThreadNum%%%'" | findstr "_progres"
set /p continue=isRunning errorlevel = %errorlevel%
if %errorlevel% neq 0 exit /b 1
exit /b 0
:startRunning
set ThreadNum=%1
set /p continue=startRunning ThreadNum is %ThreadNum%
if exist %scriptdir%\ReplBatch%ThreadNum%.bat wscript.exe %pfsdir%\invis.vbs %scriptdir%\ReplBatch%ThreadNum%.bat
set /p continue=startRunning errorlevel = %errorlevel%
exit /b 0
:isRunning
成功执行(我已在例程末尾检查了错误级别),但脚本返回后立即运行 :startRunning
。输入一些回声,set/p
我看到以下内容。我不明白为什么当我检查子例程中的错误级别时它为零,但随后线上的测试显示它为 1。
proenv>set /p continue=isRunning errorlevel = 0
isRunning errorlevel = 0
proenv>if 1 NEQ 0 exit /b 1
proenv>set ThreadNum=1
proenv>set /p continue=startRunning ThreadNum is 1
startRunning ThreadNum is 1