【问题标题】:Batch: I need some fresh eyes to see where the error isBatch:我需要一些新的眼光来看看错误在哪里
【发布时间】:2013-07-12 03:09:46
【问题描述】:

我不断收到缺少操作数错误。我似乎找不到它,但我想有一双新的眼睛可以。

@echo off

title Log Split And Backup

rem dt = date
rem tm = time
rem wd = week day
rem mh = month
rem dy = day
rem yr = year
rem hh = hour
rem mm = minute
rem ss = second
rem ms = milisecond
rem gtr = greater than
rem lss = less than
rem equ = equal to

echo Starting Log Split And Backup...
ping 1.1.1.1 -n 1 -w 1500 >nul
cls
echo Log Split And Backup Has Started...

:time
set hh=%tm:~0,2%
set mm=%tm:~3,2%
set ss=%tm:~5,2%
set ms=%tm:~7,2%
goto date

:date
set dt=%date%
set tm=%time%
set wd=%dt:~0,3%
set mh=%dt:~4,2%
set dy=%dt:~6,2%
set yr=%dt:~8,4%
goto scheduletimes

:scheduletimes
:hour1
for /f "tokens=1*delims=0" %%a in ("$0%hh%") do set /a HH=%%b
if %HH% equ 6 goto minutes1
goto hour2
:minutes1
for /f "tokens=1*delims=0" %%a in ("$0%hh%") do set /a HH=%%b
if %HH% equ 0 goto seconds1
goto hour2
:seconds1
for /f "tokens=1*delims=0" %%a in ("$0%hh%") do set /a HH=%%b
if %HH% lss 10 goto day1
goto hour2
:hour2
for /f "tokens=1*delims=0" %%a in ("$0%hh%") do set /a HH=%%b
if %HH% equ 18 goto minutes2
goto time
:minutes2
for /f "tokens=1*delims=0" %%a in ("$0%hh%") do set /a HH=%%b
if %HH% equ 0 goto seconds2
goto time
:seconds2
for /f "tokens=1*delims=0" %%a in ("$0%hh%") do set /a HH=%%b
if %HH% lss 10 goto day2
goto time

:days
:day1
for %%i in (Mon) do (
    if "%wd%"=="%%i" goto mon1
)
for %%i in (Tue) do (
    if "%wd%"=="%%i" goto tue1
)
for %%i in (Wed) do (
    if "%wd%"=="%%i" goto wed1
)
for %%i in (Thu) do (
    if "%wd%"=="%%i" goto thu1
)
for %%i in (Fri) do (
    if "%wd%"=="%%i" goto fri1
)
for %%i in (Sat) do (
    if "%wd%"=="%%i" goto sat1
)
for %%i in (Sun) do (
    if "%wd%"=="%%i" goto sun1
)

:day2
for %%i in (Mon) do (
    if "%wd%"=="%%i" goto mon2
)
for %%i in (Tue) do (
    if "%wd%"=="%%i" goto tue2
)
for %%i in (Wed) do (
    if "%wd%"=="%%i" goto wed2
)
for %%i in (Thu) do (
    if "%wd%"=="%%i" goto thu2
)
for %%i in (Fri) do (
    if "%wd%"=="%%i" goto fri2
)
for %%i in (Sat) do (
    if "%wd%"=="%%i" goto sat2
)
for %%i in (Sun) do (
    if "%wd%"=="%%i" goto sun2
)

:logsplitting
:mon1
@echo %date%
@echo %time%
echo Starting the 12hr Log Split and Log Backup...
ping 1.1.1.1 -n 1 -w 3000 >nul
xcopy "C:\Users\Kratos\Desktop\MC Server\server.txt" "C:\Users\Kratos\Dropbox\Minecraft Backups\Logs\0-mon\server1.txt" /D /E /R /I /K /Y               
del "C:\Users\Kratos\Desktop\MC Server\server.txt"
echo Finished Log Split and Log Backup...
goto time
:tue1
@echo %date%
@echo %time%
echo Starting the 12hr Log Split and Log Backup...
ping 1.1.1.1 -n 1 -w 3000 >nul
xcopy "C:\Users\Kratos\Desktop\MC Server\server.txt" "C:\Users\Kratos\Dropbox\Minecraft Backups\Logs\1-tue\server1.txt" /D /E /R /I /K /Y
del "C:\Users\Kratos\Desktop\MC Server\server.txt"
echo Finished Log Split and Log Backup...
goto time
:wed1
@echo %date%
@echo %time%
echo Starting the 12hr Log Split and Log Backup...
ping 1.1.1.1 -n 1 -w 3000 >nul
xcopy "C:\Users\Kratos\Desktop\MC Server\server.txt" "C:\Users\Kratos\Dropbox\Minecraft Backups\Logs\2-wed\server1.txt" /D /E /R /I /K /Y
del "C:\Users\Kratos\Desktop\MC Server\server.txt"
echo Finished Log Split and Log Backup...
goto time
:thu1
@echo %date%
@echo %time%
echo Starting the 12hr Log Split and Log Backup...
ping 1.1.1.1 -n 1 -w 3000 >nul
xcopy "C:\Users\Kratos\Desktop\MC Server\server.txt" "C:\Users\Kratos\Dropbox\Minecraft Backups\Logs\3-thu\server1.txt" /D /E /R /I /K /Y
del "C:\Users\Kratos\Desktop\MC Server\server.txt"
echo Finished Log Split and Log Backup...
goto time
:fri1
@echo %date%
@echo %time%
echo Starting the 12hr Log Split and Log Backup...
ping 1.1.1.1 -n 1 -w 3000 >nul
xcopy "C:\Users\Kratos\Desktop\MC Server\server.txt" "C:\Users\Kratos\Dropbox\Minecraft Backups\Logs\4-fri\server1.txt" /D /E /R /I /K /Y
del "C:\Users\Kratos\Desktop\MC Server\server.txt"
echo Finished Log Split and Log Backup...
goto time
:sat1
@echo %date%
@echo %time%
echo Starting the 12hr Log Split and Log Backup...
ping 1.1.1.1 -n 1 -w 3000 >nul
xcopy "C:\Users\Kratos\Desktop\MC Server\server.txt" "C:\Users\Kratos\Dropbox\Minecraft Backups\Logs\5-sat\server1.txt" /D /E /R /I /K /Y
del "C:\Users\Kratos\Desktop\MC Server\server.txt"
echo Finished Log Split and Log Backup...
goto time
:sun1
@echo %date%
@echo %time%
echo Starting the 12hr Log Split and Log Backup...
ping 1.1.1.1 -n 1 -w 3000 >nul
xcopy "C:\Users\Kratos\Desktop\MC Server\server.txt" "C:\Users\Kratos\Dropbox\Minecraft Backups\Logs\6-sun\server1.txt" /D /E /R /I /K /Y
del "C:\Users\Kratos\Desktop\MC Server\server.txt"
echo Finished Log Split and Log Backup...
goto time
:mon2
@echo %date%
@echo %time%
echo Starting the 12hr Log Split and Log Backup...
ping 1.1.1.1 -n 1 -w 3000 >nul
xcopy "C:\Users\Kratos\Desktop\MC Server\server.txt" "C:\Users\Kratos\Dropbox\Minecraft Backups\Logs\0-mon\server2.txt" /D /E /R /I /K /Y
del "C:\Users\Kratos\Desktop\MC Server\server.txt"
echo Finished Log Split and Log Backup...
goto time
:tue2
@echo %date%
@echo %time%
echo Starting the 12hr Log Split and Log Backup...
ping 1.1.1.1 -n 1 -w 3000 >nul
xcopy "C:\Users\Kratos\Desktop\MC Server\server.txt" "C:\Users\Kratos\Dropbox\Minecraft Backups\Logs\1-tue\server2.txt" /D /E /R /I /K /Y
del "C:\Users\Kratos\Desktop\MC Server\server.txt"
echo Finished Log Split and Log Backup...
goto time
:wed2
@echo %date%
@echo %time%
echo Starting the 12hr Log Split and Log Backup...
ping 1.1.1.1 -n 1 -w 3000 >nul
xcopy "C:\Users\Kratos\Desktop\MC Server\server.txt" "C:\Users\Kratos\Dropbox\Minecraft Backups\Logs\2-wed\server2.txt" /D /E /R /I /K /Y
del "C:\Users\Kratos\Desktop\MC Server\server.txt"
echo Finished Log Split and Log Backup...
goto time
:thu2
@echo %date%
@echo %time%
echo Starting the 12hr Log Split and Log Backup...
ping 1.1.1.1 -n 1 -w 3000 >nul
xcopy "C:\Users\Kratos\Desktop\MC Server\server.txt" "C:\Users\Kratos\Dropbox\Minecraft Backups\Logs\3-thu\server2.txt" /D /E /R /I /K /Y
del "C:\Users\Kratos\Desktop\MC Server\server.txt"
echo Finished Log Split and Log Backup...
goto time
:fri2
@echo %date%
@echo %time%
echo Starting the 12hr Log Split and Log Backup...
ping 1.1.1.1 -n 1 -w 3000 >nul
xcopy "C:\Users\Kratos\Desktop\MC Server\server.txt" "C:\Users\Kratos\Dropbox\Minecraft Backups\Logs\4-fri\server2.txt" /D /E /R /I /K /Y
del "C:\Users\Kratos\Desktop\MC Server\server.txt"
echo Finished Log Split and Log Backup...
goto time
:sat2
@echo %date%
@echo %time%
echo Starting the 12hr Log Split and Log Backup...
ping 1.1.1.1 -n 1 -w 3000 >nul
xcopy "C:\Users\Kratos\Desktop\MC Server\server.txt" "C:\Users\Kratos\Dropbox\Minecraft Backups\Logs\5-sat\server2.txt" /D /E /R /I /K /Y
del "C:\Users\Kratos\Desktop\MC Server\server.txt"
echo Finished Log Split and Log Backup...
goto time
:sun2
@echo %date%
@echo %time%
echo Starting the 12hr Log Split and Log Backup...
ping 1.1.1.1 -n 1 -w 3000 >nul
xcopy "C:\Users\Kratos\Desktop\MC Server\server.txt" "C:\Users\Kratos\Dropbox\Minecraft Backups\Logs\6-sun\server2.txt" /D /E /R /I /K /Y
del "C:\Users\Kratos\Desktop\MC Server\server.txt"
echo Finished Log Split and Log Backup...
goto time

感谢所有查看整个代码的人,特别感谢为我找到错误的人。

【问题讨论】:

    标签: batch-file command dos timed operand


    【解决方案1】:

    如果上面的代码是你的完整程序,那么tm变量在使用前还没有赋值。我认为这一行:

    set tm=%time%
    

    需要移到:time标签下面...

    【讨论】:

    • 非常感谢。是的,我是盲人哈哈。我有一组tm=%time% 日期不足。我重写并切换了时间部分和日期部分,这一定是导致错误的原因。我的新眼睛可以解决我的问题。
    • 修复了整体 Missing Operand 错误,但现在似乎还有另一个地方,在它当时执行命令并且秒数到达窗口外之后,我仍然得到一个 Missing Operand。我把它缩小到这一行::minutes1 for /f "tokens=1*delims=0" %%a in ("$0%mm%") do set /a MM=%%b if %MM% equ 0 goto seconds1 goto hour2(这是不同的,因为我发布的代码不适用于不知道如何编码的人,所以他们不能窃取它)根据日志它不是将 MM 设置为 %mm%,由于未设置 MM,因此会出现该错误。
    • 这个新错误的问题可以在Link找到。这也会为您提供有关错误的更多信息。
    【解决方案2】:

    本质上,此代码应该替换您的重复代码,并且还使用 Wmic(XP Pro 和更高版本)提供一组可靠的时间和日期变量(零填充)。

    这在 xcopy 例程中使用变量 %var%%server%

    您的:scheduletimes 例程看起来很古怪,因为您似乎在设置和重置一个名为%hh% 的变量,并且一次又一次地测试同一个变量。

    如果您提供有关计划时间的信息,那么这也可能会被简化。

    @echo off
    
    title Log Split And Backup
    
    rem wd = week day
    rem mh = month
    rem dy = day
    rem yr = year
    rem hh = hour
    rem mm = minute
    rem ss = second
    rem ms = milisecond
    rem gtr = greater than
    rem lss = less than
    rem equ = equal to
    
    echo Starting Log Split And Backup...
    ping -n 1 localhost >nul
    cls
    echo Log Split And Backup Has Started...
    
    :time
    for /f "delims=" %%a in ('wmic OS Get localdatetime  ^| find "."') do set dt=%%a
    set Yr=%dt:~0,4%
    set Mh=%dt:~4,2%
    set Dy=%dt:~6,2%
    set HH=%dt:~8,2%
    set MM=%dt:~10,2%
    set SS=%dt:~12,2%
    set MS=%dt:~15,2%
    
    :date
    set dt=%date%
    set wd=%dt:~0,3%
    
    
    :scheduletimes
    :hour1
    for /f "tokens=1*delims=0" %%a in ("$0%hh%") do set /a HH=%%b
    if %HH% equ 6 goto minutes1
    goto hour2
    :minutes1
    for /f "tokens=1*delims=0" %%a in ("$0%hh%") do set /a HH=%%b
    if %HH% equ 0 goto seconds1
    goto hour2
    :seconds1
    for /f "tokens=1*delims=0" %%a in ("$0%hh%") do set /a HH=%%b
    if %HH% lss 10 set server=server1
    goto hour2
    :hour2
    for /f "tokens=1*delims=0" %%a in ("$0%hh%") do set /a HH=%%b
    if %HH% equ 18 goto minutes2
    goto time
    :minutes2
    for /f "tokens=1*delims=0" %%a in ("$0%hh%") do set /a HH=%%b
    if %HH% equ 0 goto seconds2
    goto time
    :seconds2
    for /f "tokens=1*delims=0" %%a in ("$0%hh%") do set /a HH=%%b
    if %HH% lss 10 set server=server2
    
        if "%wd%"=="MON" set var=0-%wd%
        if "%wd%"=="TUE" set var=1-%wd%
        if "%wd%"=="WED" set var=2-%wd%
        if "%wd%"=="THU" set var=3-%wd%
        if "%wd%"=="FRI" set var=4-%wd%
        if "%wd%"=="SAT" set var=5-%wd%
        if "%wd%"=="SUN" set var=6-%wd%
    
    :logsplitting
    
    echo %date%
    echo %time%
    echo Starting the 12hr Log Split and Log Backup...
    ping -n 1 localhost >nul
    xcopy "C:\Users\Kratos\Desktop\MC Server\server.txt" "C:\Users\Kratos\Dropbox\Minecraft Backups\Logs\%var%\%server%.txt" /D /E /R /I /K /Y               
    del "C:\Users\Kratos\Desktop\MC Server\server.txt"
    echo Finished Log Split and Log Backup...
    goto time
    

    【讨论】:

      【解决方案3】:

      好吧,您可以通过使用调试来查看您的错误。 请执行以下操作:

      > bash -x script1.sh
      

      请查看以下网址了解更多详情。

      http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_02_03.html

      【讨论】:

      • 我不认为 bash 可以调试批处理文件 ;-)
      • 从表面上看,这毫无用处,因为它似乎不适用于批处理文件。
      猜你喜欢
      • 1970-01-01
      • 2020-12-22
      • 1970-01-01
      • 1970-01-01
      • 2016-06-29
      • 1970-01-01
      • 1970-01-01
      • 2010-09-21
      • 1970-01-01
      相关资源
      最近更新 更多