为什么此批处理脚本崩溃?

时间:2015-09-08 18:38:07

标签: batch-file winapi

这是一个简单的批处理文件,用于显示电量不足的通知。它的组成部分是通过观察其他民族而得出的。发布和测试。我很困惑,但我想我在添加'hasBeenNotified'检查。

@ECHO OFF
setlocal
set multipleNotification=5
set BatteryLevel=-1
set notificationThreshold=20
set hasBatteryNotified=0
:: if on battery
wmic Path Win32_Battery Get BatteryStatus | find "2" > nul
if %errorlevel% neq 0 (

    :: if battery level low, notify
    for /f %%a in ('wmic.exe path Win32_Battery get EstimatedChargeRemaining ^| findstr.exe /r "[0-9][0-9]*"') do set BatteryLevel=%%a
    set /a notMultiple = %BatteryLevel% %% %multipleNotification%
    if %BatteryLevel% leq %notificationThreshold% if %notMultiple%==0(

        :: if not notified
        if %hasBatteryNotified%==0(
            start cmd /K echo Batery is at %BatteryLevel%!!
            set hasBatteryNotified=1
        )
    ) else (
        set hasBatteryNotified=0
    )
) else (
    set hasBatteryNotified=0
)

1 个答案:

答案 0 :(得分:1)

if %hasBatteryNotified%==0 (

if %BatteryLevel% leq %notificationThreshold% if %notMultiple%==0 (

(之前必须有空格(是的,Batch对空格非常挑剔)