批处理文件命令执行超时

问题描述

我有一个批处理文件,该文件可编译项目,然后运行连接到DSP的JS,运行程序并从DSP的内存中读取结果(有关DSP等的更多详细信息,请参见我的问题结尾) )。 我的问题是编译和JS运行在批处理文件中的一个循环中运行,有时由于某种原因,构建卡住了,抛出了DSP异常或DSP陷入了阻止批处理的情况继续循环的下一步。 我要实现的是我的批处理文件中的某种看门狗,它可使当前循环步骤持续有限的时间,如果该时间到期,则继续进行下一步。

DSP是TI6678EVM,使用CodeComposer v5.3和DSS。 批处理文件的循环:

:CREATE_TEST_DIR
SET "test_dir=%cur_dir%%proj_name%"
ECHO %test_dir%
IF NOT EXIST %test_dir% GOTO INC_TESTN

ECHO ************************************************************************
ECHO copying headers from %headers_folder_name%%test_num%
ECHO ************************************************************************
SET /a Idx=10
:CHANGE_HEADERS
REM Delete the header files from project dir
del %test_dir%\HeaderFiles\R_Main_%Idx%.h"
REM copy test vectors header file to workspace
copY /y "%test_dir%\%headers_folder_name%%test_num%\R_Main_%Idx%_%test_num%.h" "%test_dir%\HeaderFiles\R_Main_%Idx%.h"
SET /a Idx+=1
IF %Idx% leq 16 GOTO CHANGE_HEADERS


ECHO ************************************************************************
ECHO Building project
ECHO ************************************************************************
REM Create and build project
CALL "%eclipsec_path%" -noSplash -data "%test_dir%" -application com.ti.ccstudio.apps.projectBuild -ccs.workspace -ccs.buildType clean > "%test_dir%\p_build.log" || GOTO FAIL_BUILD
CALL "%eclipsec_path%" -noSplash -data "%test_dir%" -application com.ti.ccstudio.apps.projectBuild -ccs.workspace > "%test_dir%\p_build.log" || GOTO FAIL_BUILD
REM ECHO Project build successful


FOR /r "%test_dir%" %%a in (*.ccxml) do set CCXML_path=%%~dpnxa
IF "%CCXML_path%"=="" GOTO BAD_CCXML
ECHO Found .ccxml file %CCXML_path%
FOR /r "%test_dir%" %%a in (*.out) do set OUT_path=%%~dpnxa
IF "%OUT_path%"=="" GOTO BAD_OUT
ECHO Found .out file %OUT_path%

SET "testVecPath=%test_dir%\%headers_folder_name%%test_num%"
ECHO ************************************************************************
ECHO Runing tet
ECHO ************************************************************************
CALL "%dss_path%" "ccsRunTestVectors.js" %ccs_path% %test_dir% %CCXML_path% %OUT_path% %datetimef% %testVecPath%|| GOTO FAIL_BASIC
ECHO ************************************************************************
ECHO Test Done.
ECHO ************************************************************************
GOTO INC_TESTN

:FAIL_CREATE
ECHO Failed

:INC_TESTN
SET /a test_num+=1
REM pause
IF %test_num% gtr %TestNumEnd% GOTO DONE
GOTO CREATE_TEST_DIR

:DONE

解决方法

这里是我的意思的示例,只要timer.cmd文件处于活动状态且标题为Timer,它将运行主循环。您可以按原样复制并调用类似test_wait.cmd的代码,然后运行它,您将看到它会继续循环,echo只要Still running脚本就timer.cmd正在运行,通过此脚本为您创建的方式。

然后您可以根据需要将其合并到脚本中。

@echo off
echo title Timer>timer.cmd
echo timeout 20 /NOBREAK ^>nul>>timer.cmd
echo exit>>timer.cmd
start /min timer.cmd & timeout 1 /NOBREAK>nul
:start
tasklist /FI "windowtitle eq Timer" | findstr /i "cmd.exe">nul 2>&1
if errorlevel 1 goto del timer.cmd /Q & goto :eof
echo Still running..
(timeout /t 1)>nul
goto :start