【问题标题】:Batch script does not get the return value from exe file批处理脚本没有从 exe 文件中获取返回值
【发布时间】:2017-02-28 07:17:08
【问题描述】:

我想使用批处理脚本来启动两个 exe 文件。脚本应该将第一个 exe 程序 1 的输出(返回值)变为红色,如果返回值为“0”则应执行另一个 exe 程序 2,否则如果第一个 exe 程序 1 的返回值为“1”则不应该,只是执行第一个程序1。我有一个脚本,但在“0”的情况下它永远不会跳转到第二个 exe 程序 2。有什么帮助吗?这里是脚本

REM for every file do:
for %%a in (*.*) do (   
  REM get last line [reference filename with %%a]
  for /f %%b in ('C:\program1.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:
start C:\Program2.exe %1
goto :eof

【问题讨论】:

  • 返回值还是输出?这很重要。
  • 好的。所以exe文件是OpenCV程序来检测对象。因此,如果成功检测到对象,则 OpenCV 程序 1 应该输出 1,否则输出 0。在我使用 cout 的程序中。它的 C++ OpenCV 程序因此基于如果检测到不是对象我想调用另一个 OpenCV 程序
  • 好的。所以exe文件是OpenCV程序来检测对象。因此,如果成功检测到对象,则 OpenCV 程序 1 应该输出 1,否则输出 0。在我使用 cout 的程序中。它的 C++ OpenCV 程序因此基于是否在 OpenCv 程序 1 中检测到对象,我想调用另一个 OpenCV 程序 2。希望现在更清楚
  • 如果这是整个脚本,那么您在它的开头缺少setlocal EnableDelayedExpansion
  • 我不熟悉批处理脚本。这就是我所拥有的一切。所以我需要整个脚本代码来解决我的问题。请您发布所有有效的脚本代码吗?

标签: windows batch-file


【解决方案1】:

您将括号中的 var 传递给 :dothis 并 start 使用括号中的第一个参数作为窗口标题,因此 Program2 不会获得任何参数。

:dothis
REM execute second program with filename as parameter:
start "" "C:\Program2.exe" %1

【讨论】:

    猜你喜欢
    • 2014-12-31
    • 1970-01-01
    • 1970-01-01
    • 2013-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-06
    • 1970-01-01
    相关资源
    最近更新 更多