如果program1 exe的输出为0,则运行另一个exe

时间:2017-02-13 08:14:26

标签: windows batch-file

我正在使用Windows 8,并希望有一个依赖于exe文件输出的批处理文件将调用另一个exe文件。所以exe文件的输出是1或0.它是openCV文件,如果程序检测到某个对象,那么输出是1,如果不是那么0.我写了脚本,但它不会在输出的情况下调用另一个程序程序1是0.任何帮助吗?

这里是批处理文件

   @echo off
   for /f "delims=" %%a in ('C:\Users\myProgram1.exe -a -b -c') do if /i "%%~a"=="errorlevel" (call:dothis) 
if %errorlevel%==0 call:dothis
goto:eof

:dothis
C:\Users\myProgram2.exe
exit /b 0

我只能运行OpenCVprgram1.exe(第一个程序),但在输出0时从不执行OpenCVprgram2.exe。有什么帮助?

此处运行此脚本时myProgram1的输出

@echo off
C:\Users\myProgram1.exe > result.txt
set DATA=<result.txt
echo %DATA%
del result.txt

未检测到特征的输出为0。如此截图所示 Output of program 1 is 0

如果检测到的功能为1,则如此图所示 Output of program1 is 1

1 个答案:

答案 0 :(得分:0)

根据您对问题的最新更改和您的意见,以下内容应该非常接近您想要的内容。

REM for every file do:
for %%a in (*.*) do (   
  REM get last line [reference filename with %%a]
  for /f %%b in ('myProgram1.exe -a -b -c "%%~a"`) do set lastLine=%%b
  REM check for "0":
  if "!lastLine!"=="0" (
    REM call with filename as parameter:
    call :dothis "%%~a"
  ) else (
    echo %%a nothing to do
  )
)
goto :eof

:dothis
REM execute second program with filename as parameter:
myProgram2.exe %1
goto :eof

请尝试报告

相关问题