【问题标题】:How can I make the find function not display anything on the command line?如何使 find 函数在命令行上不显示任何内容?
【发布时间】:2016-09-13 19:59:15
【问题描述】:

这是我得到的:

SCHTASKS /query /tn "test" | find /c "Running" &&(
goto finish
)||(
SCHTASKS /create /tn "test" /sc minute /mo 10 /tr c:\bin\go.vbs
)

:finish
echo.
echo Done
echo.
timeout 3

我想检查test 任务是否已经在运行。此功能有效,但即使关闭回显,find /c 部分仍会返回 1 或 0,具体取决于任务是否正在运行。

有没有办法让它在我在命令行中运行时不会打印出 1 或 0?

【问题讨论】:

    标签: batch-file find windows-task-scheduler


    【解决方案1】:

    最终这样做了:

    SCHTASKS /query  | findstr /n "test" &&(
    goto finish
    )||(
    SCHTASKS /create /tn "test" /sc minute /mo 10 /tr c:\bin\go.vbs
    )
    
    :finish
    echo.
    echo Done
    echo.
    timeout 3
    

    【讨论】:

      【解决方案2】:
      | find /c "Running">Nul 2>&1&&(
      

      如上进行更改。

      您的脚本也可能像这样更好:

      SCHTASKS /query /tn "test" | find /c "Running">Nul 2>&1&&(goto :finish)
      SCHTASKS /create /tn "test" /sc minute /mo 10 /tr c:\bin\go.vbs
      
      :finish
      echo.
      echo Done
      echo.
      timeout 3
      

      【讨论】:

      • 虽然它不显示 1 和 0,但当我第一次运行它时,它确实给出了 ERROR: The system cannot find the file specified.
      • 我的回答是针对您的具体问题的解决方案。您说您的脚本正在运行,我没有添加任何可能影响脚本的内容,以便它可以输出您报告的错误。
      猜你喜欢
      • 2020-05-23
      • 2012-01-06
      • 1970-01-01
      • 2013-02-13
      • 2022-11-15
      • 2020-08-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多