1

バッチ スクリプトに関するヘルプが必要です。それは完全に実行されていましたが、後で実行したいときに、表示された前の結果を繰り返し続けました。たとえば、先週実行したプログラムは echo "The program run at first last week" で、今日実行しようとしたときには echo "This is today" でした。実行して前回の結果を表示しました」

PSコードは現在完全に機能しています.... @echo off

SETLOCAL ENABLEDELAYEDEXPANSION
set file="C:\compress.gdb"


if not exist %file% goto :EOF
FOR %%A IN (%file%) DO set size=%%~zA

>"%temp%\math.vbs" echo Set objArgs = WScript.Arguments: num = objArgs(0) : result = 0
>>"%temp%\math.vbs" echo if num ^> 1073741824 then result=1
>>"%temp%\math.vbs" echo if num ^> 6442450944 then result=2
>>"%temp%\math.vbs" echo Wscript.echo result

for /f %%a in ('cscript /nologo "%temp%\math.vbs" %size% ') do set z=%%a

del "%temp%\math.vbs"

:: z will be 2 if %size% greater than 6442450944
:: z will be 1 if %size% greater than 1073741824
:: z will be 0 if %size% less    than 1073741825

echo %z%

if %z% EQU 2 (goto EXECUTE)
if %z% EQU 0 (goto LOGOUT)
if %z% EQU 1 (goto LOGOUT)

goto :EOF

:EXECUTE

call "C:\Batch_Scripts_Sensitive\message.rtf" /max
"C:\Program Files\Embarcadero\InterBase\bin\isql" -i "C:\Batch_Scripts_Sensitive\Empty_Tables_2.sql" localhost:"C:\Program Files (x86)\GE Aviation\AB139 HGS\DB\compress.GDB" -user xxxxxxx -pass xxxxxxx

:: Create Date for Back up and Restore

set hour=%time:~0,2%
if "%hour:~0,1%" == " " set hour=0%hour:~1,1%
echo hour=%hour%
set min=%time:~3,2%
if "%min:~0,1%" == " " set min=0%min:~1,1%
echo min=%min%
set secs=%time:~6,2%
if "%secs:~0,1%" == " " set secs=0%secs:~1,1%
echo secs=%secs%

set year=%date:~-4%
echo year=%year%
set month=%date:~3,2%
if "%month:~0,1%" == " " set month=0%month:~1,1%
echo month=%month%
set day=%date:~0,2%
if "%day:~0,1%" == " " set day=0%day:~1,1%
echo day=%day%

rem use this if you want to add seconds rem set datetimef=mydate_%year%_%month%_%day%_%hour%:%min%:%secs%
set datetimef=%year%_%month%_%day%_%hour%%min%
echo datetimef=%datetimef%
mkdir "C:\Monthly-gdb-restore\%datetimef%"


copy "C:\compress.gdb" "C:\Monthly-gdb-restore\%datetimef%" /Y


:: Delete empty folder in this location %Datetime%

for /f "delims=" %%d in ('dir "C:\Monthly-gdb-restore" /s /b /ad ^| sort /r') do rd "%%d"


forfiles /P "C:\Monthly-gdb-restore"  /S /M *.gdb /D -7 /C "cmd /c del @PATH /q"

"C:\Program Files\Embarcadero\InterBase\bin\gbak"   -b "C:\compress.gdb" "C:\compress.ibk"  -user xxxxxxx -password xxxxxxx

set hour=%time:~0,2%
if "%hour:~0,1%" == " " set hour=0%hour:~1,1%
echo hour=%hour%
set min=%time:~3,2%
if "%min:~0,1%" == " " set min=0%min:~1,1%
echo min=%min%
set secs=%time:~6,2%
if "%secs:~0,1%" == " " set secs=0%secs:~1,1%
echo secs=%secs%

set year=%date:~-4%
echo year=%year%
set month=%date:~3,2%
if "%month:~0,1%" == " " set month=0%month:~1,1%
echo month=%month%
set day=%date:~0,2%
if "%day:~0,1%" == " " set day=0%day:~1,1%
echo day=%day%

rem use this if you want to add seconds rem set datetimef=mydate_%year%_%month%_%day%_%hour%:%min%:%secs%
set datetimef=%year%_%month%_%day%_%hour%%min%
echo datetimef=%datetimef%
mkdir "C:\Monthly-ibk-backup\%datetimef%"

copy "C:\compress.ibk"   "C:\Monthly-ibk-backup\%datetimef%"  /Y

:: Delete empty folder in this location %Datetime%

for /f "delims=" %%d in ('dir "C:\Monthly-ibk-backup" /s /b /ad ^| sort /r') do rd "%%d"

forfiles /P "C:\Monthly-ibk-backup"  /S /M *.ibk /D -7 /C "cmd /c del @PATH /q"

"C:\Program Files\Embarcadero\InterBase\bin\gbak"  -R "C:\compress.ibk" "C:\compress.gdb" -user xxxxxxx -password xxxxxxx

 goto FINISH


:LOGOUT

Echo " The size of the database file is not up to 6GB

goto :EOF

:FINISH

ECHO " The database for xxxxxxx  was up to 6GB OR MORE, therefore proper backup and restoration has been performed.





goto :EOF
4

2 に答える 2

7

の数set minbytesize=6442450944が大きすぎます。
バッチは 32 ビットの数値のみを処理できます。

ただし、数値を引用すると、文字列比較関数が使用されるため、 のサイズは"9"よりも大きくなり"6442450944"ます。

正しい比較を行うには、数値の前にゼロを付けることができます。この場合、2 番目の数値の長さがわかっているので簡単です。

...
set "size=000000000000%size%"
set "size=%size:~-10%"
if "%size%" GEQ "%minbytesize%" (goto EXECUTE) 

これはまだ文字列の比較ですが、現在は数値に対しても正しいです。

ところで。これはあなたの主な問題ではありません。問題が発生する場所を確認する
ように設定することをお勧めします。ECHO ON

使用している時間形式は何ですか?
問題が発生した時間に接頭辞ゼロを使用している場合set /a hh=%hh%+100

于 2013-06-19T14:14:59.580 に答える
4

両方とも同じコンソール ウィンドウで実行している場合、問題は初期化されていない変数である可能性が高く、最後の結果が表示されます。

VBS を使用して数値を確認するには、コードの最初の部分としてこれを試してください。最後に残してgoto :eof、次のコードへの比較を通過しないようにします。

最終的な比較をチェックして、彼らがあなたが望むことをしていることを確認してください。

@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
set file="C:\Program Files (x86)\GE Aviation\AB139 HGS\DB\AW139 DB.gdb"


if not exist %file% goto :EOF
FOR %%A IN (%file%) DO set size=%%~zA

>"%temp%\math.vbs" echo Set objArgs = WScript.Arguments: num = objArgs(0) : result = 0
>>"%temp%\math.vbs" echo if num ^> 1073741824 then result=1
>>"%temp%\math.vbs" echo if num ^> 6442450944 then result=2
>>"%temp%\math.vbs" echo Wscript.echo result

for /f %%a in ('cscript /nologo "%temp%\math.vbs" %size% ') do set z=%%a

del "%temp%\math.vbs"

:: z will be 2 if %size% greater than 6442450944
:: z will be 1 if %size% greater than 1073741824
:: z will be 0 if %size% less    than 1073741825

if %z% EQU 2 (goto EXECUTE) 
if %z% EQU 1 (goto EXECUTE) 
if %z% EQU 0 (goto LOGOUT)

goto :EOF
于 2013-06-19T14:01:04.233 に答える