| 1. |
Solve : Batch file Var output help needed? |
|
Answer» I need a few things echo. this is a test 1. pass literal strings Code: [Select]echo. this is a test call :test test1 call :test test2 call :test test3 :end 2. pass variables Code: [Select]echo. this is a test call :test %test1% call :test %test2% call :test %test3% :end Either case, subroutine shows what is passed: Code: [Select]:test1 echo. This is %1 goto :eofThanks for your help. That work like i needed. now another question about var's im doing the following subroutine: Code: [Select] call :s1ofc "Server 1" PING 192.168.1.110 -n 1| FIND "bytes=" > NUL call :s2ofc "Server 1" XCOPY *.* "\\192.168.1.110\C$\Test Folder" /EXCLUDE:copyfiles.cfg /s/y/z/v/k call :s3ofc "Server 1" GOTO :EOF ::===========================:: :: Screen1 ouput for copying :: ::===========================:: :s1ofc echo. echo. ----------------------------------------------- echo. echo. Copying files to %1 echo. echo. Connecting to %1... GOTO :EOF ::===========================:: :: Screen2 ouput for copying :: ::===========================:: :s2ofc IF ERRORLEVEL 1 ECHO. Connection failed... && ECHO. Skipping %1...&& echo %date% %time% Connecting to %1 failed>> .\LOG.TXT && ECHO. && GOTO :EOF echo. Connection established... echo. echo. Copying STARTED... echo. pause GOTO :EOF ::===========================:: :: Screen3 ouput for copying :: ::===========================:: :s3ofc echo. if errorlevel 4 echo "An error has be found" && echo. Please check the log.txt file. && echo %date% %time% Insufficient disk access, space, on %1>> .\LOG.TXT if errorlevel 5 echo echo %date% %time% Disk write error occur99red on %1>> .\LOG.TXT echo. echo. Copying files to %1 Complete... PING 1.0.0.0 -n 1 -w 2000 >NUL GOTO :EOF I need help with my if errorlevel's I want that If the errorlevel is true that on that line i can enter in a var and pass it back to the original routine to run an if STATEMENT. Code: [Select]call :s1ofc "Server 1" PING 192.168.1.110 -n 1| FIND "bytes=" > NUL IF erq1=1 goto: eof call :s2ofc "Server 1" XCOPY *.* "\\192.168.1.110\C$\Test Folder" /EXCLUDE:copyfiles.cfg /s/y/z/v/k call :s3ofc "Server 1" GOTO :EOF ::===========================:: :: Screen2 ouput for copying :: ::===========================:: :s2ofc set erq1=0 IF ERRORLEVEL 1 ECHO. Connection failed... && ECHO. Skipping %1...&& echo %date% %time% Connecting to %1 failed>> .\LOG.TXT && ECHO. && erq1=1 && GOTO :EOF echo. Connection established... echo. echo. Copying started... echo. pause GOTO :EOF but for some reason erq1 always equals 0 Thoughts?if you use the archaic obsolete MS-DOS method in this format: (N is a number) IF ERRORLEVEL N action You need to understand that the test is passed if the errorlevel is N or greater. Thus if you are testing for different errorlevels you have to do the tests in descending order. The action is usually GOTO a label because otherwise every level below the one you want will be executed also. (do you understand why?) if errorlevel 5 action if errorlevel 4 action if errorlevel 3 action if errorlevel 2 action if errorlevel 1 action Better to use the (since Windows 2000) NT type errorlevel variable where the order does not matter and you can specify more tests and the test can be exactly what you want e.g. if %errorlevel% equ 4 action if %errorlevel% gtr 0 action Also, in Windows, && does not mean what you think it does. ok i see why i would want to use %errorlevel% how would i fix this line if i should not use &&? Code: [Select]if %errorlevel% 5 echo echo %date% %time% Disk write error occurred on %1>> .\LOG.TXT if %errorlevel% 4 echo "An error has be found" && echo. Please check the log.txt file. && echo %date% %time% Insufficient disk access, space, on %1>> .\LOG.TXT Now is there anyway to output a list of files that have an error? Currently it will only tell me that there was an error but not what files were the cause. Is there something better to use than xcopy? (FREE for commercial use) Running on XP win7 server2003 & server2008 Quote how would i fix this line if i should not use &&? Just use one ampersand (&) if you merely want to join commands in one line In Unix and Windows & is the command separator command1 & command2 means "execute command1 and then execute command2" && is a conditional EXECUTION operator command1 && command2 means "execute command1 and if command1 returns a zero errorlevel then execute command2" The opposite is || command1 || command2 means "execute command1 and if command1 returns a non-zero errorlevel then execute command2" Quote Is there something better to use than xcopy? (Free for commercial use) Many people like Robocopy Thanks |
|