Jump to content

Recommended Posts

Posted

Hi everyone, I'm learning programming with AUTOIT. I've put four lines of code in it to perform backups with the Windows 10 "Robocopy" command. I intercept an ERROR string in the log file, but sometimes it gives false errors, definitely because I didn't write it well. For this reason, I'd like your help in learning how to intercept the error and the exit code well. I tried writing it with windows script commands and it seems to work fine and also with AUTOIT but I think you need to change the interception method. I'll put the scripts in there. Thanks to anyone who would like to help me.parzial.batparzial.au3

Posted

...

robocopy "%SOURCE%" "%DEST%\Backup_Archivio" /E /Z /XJ /R:3 /W:5 /COPY:DAT /TEE /V /X /LOG:"%LOGFILE%"

echo.
echo =====================================
echo Controllo Errori di copia:
findstr /C:"ERROR" "%LOGFILE%"
echo.

if %ERRORLEVEL% EQU 0 set ESITO=OK: Niente da copiare
if %ERRORLEVEL% EQU 1 set ESITO=OK: File copiati correttamente
if %ERRORLEVEL% EQU 3 set ESITO=OK: File e cartelle copiate
if %ERRORLEVEL% EQU 8 set ESITO=OK: Backup ok, 1 file saltato - vedi percorso sopra
if %ERRORLEVEL% GEQ 9 set ESITO=ERRORE GRAVE: Backup fallito

echo %ESITO%
echo Codice uscita: %ERRORLEVEL%
echo =====================================

powershell -c "(New-Object Media.SoundPlayer 'C:\Windows\Media\Windows Background.wav').PlaySync()"
powershell -c "[System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms'); [System.Windows.Forms.MessageBox]::Show('%ESITO%', 'Backup Archivio')"

pause

 

AUTOIT script:

; Controlla errori nel file di log
    ;Local $sLogContent = FileRead($logFile)
    If StringInStr($sLogContent, "ERRORE") Then
        _GIF_DeleteGIF($hGIF) ; Cancella la gif di attesa dalla form
        MsgBox($MB_ICONERROR, "FREDDIS backup", "Si è verificato un errore durante il backup." & @CRLF & "Codice uscita: "  & @CRLF & "Controlla il file log: " & $logfile)
        Exit
    Else
        _GIF_DeleteGIF($hGIF)
        MsgBox($MB_ICONINFORMATION, "FREDDIS backup", "Backup completato correttamente.")
        Exit
    EndIf

 

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...