【问题标题】:Batch file - check output of exe批处理文件 - 检查 exe 的输出
【发布时间】:2013-10-13 13:54:48
【问题描述】:

我以前没有使用过批处理文件,但我想创建一个批处理文件来运行命令行程序,该程序将根据成功或失败输出两行之一。有什么方法可以捕获可执行文件的输出而不将其写入临时文件?

提前致谢

【问题讨论】:

    标签: batch-file command-line executable


    【解决方案1】:

    将程序放入for /f循环中(示例):

    for /f "delims=" %%a in ('myProgram.exe -a -b -c') do if /i "%%~a"=="failure" (call:dothis) else call:success
    if %errorlevel%==0 call:success
    if %errorlevel%==1 call:dothis
    goto:eof
    
    :dothis
    echo Error found.
    exit /b 1
    
    :success
    echo No error found.
    exit /b 0
    

    【讨论】:

    • 感谢您的回答。我已经稍微适应了代码以满足我的需要,但这非常有帮助
    猜你喜欢
    • 2010-09-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多