【问题标题】:Time based cmd exit基于时间的 cmd 退出
【发布时间】:2014-11-03 23:31:11
【问题描述】:

我正忙于开发一个 cmd 程序(使用 Windows & 并以管理员身份运行 cmd),它将执行以下操作:

  • 检测所有连接到网络的计算机并写入文本文件(这部分功能正常)
  • 如果计算机时间相同,例如下午 12:00,则退出程序

程序如下:

@ECHO OFF

color a

: Begin

IF %Time% /t GTQ 01:15 && %Time% /t LEQ 01:20 (GOTO END) <---- problem is here

%                                                                                             %
% Date stamp the log entry and copy values. Wait 3 min before redoing the scan and check time %
%                                                                                             %

Time /t >> C:\Users\Paimon\Desktop\"WIFI data.txt"

Date /t >> C:\Users\Paimon\Desktop\"WIFI data.txt"

netstat -n

netstat -n >> C:\Users\Paimon\Desktop\"WIFI data.txt"

timeout /t 180

cls

GOTO Begin

:END
exit

我决定将时间与一个剧烈的值进行比较,因为程序每 3 分钟只执行一次特定的行。

【问题讨论】:

    标签: windows if-statement time cmd compare


    【解决方案1】:

    你的问题行有几个问题:

    %time% /t 不起作用

    GTQ 不是允许的运算符(使用 GTR 或 GEQ)

    你不能if a &amp;&amp; b then

    一个好的解决方案是:

    if %time: =0% geq 01:15 if %time: =0% leq 01:20 goto end
    

    【讨论】:

    • +1,对所提问题的出色简单解决方案。
    • 我担心,Stephan,如果我将您的代码插入到我现有的代码中,cmd 会返回错误:此时 72 是意外的。
    • 72?七十二?使用此代码没有机会得到该错误。删除@echo off 看看会发生什么。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-04
    • 2019-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多