【问题标题】:Batch file command execution timeout批处理文件命令执行超时
【发布时间】:2020-08-19 07:28:38
【问题描述】:

我有一个批处理文件,它编译一个项目,然后运行一个连接到 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

【问题讨论】:

  • timeout 10 /nobreak >nul
  • @Gerhard 这将暂停批处理运行。我需要的是,只要未达到超时,批处理就可以继续运行
  • 创建一个该文件调用的批处理文件,在该批处理文件中使用timeout并给它一个标题,在你的循环中使用tasklist来查看那个windowtitled进程是否仍在运行,如果没有那么退出。

标签: batch-file watchdog texas-instruments code-composer


【解决方案1】:

这是我的意思的一个示例,只要timer.cmd 文件处于活动状态,标题为Timer,它就会运行主循环。您可以按原样复制它并将其命名为 test_wait.cmd 然后运行它,您会看到它会继续循环,echoing 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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-24
    • 1970-01-01
    • 2018-12-25
    • 2013-07-23
    相关资源
    最近更新 更多