@echo off setlocal enabledelayedexpansion :start cls echo. echo SUPPORT TOOLS LOW COST…
- User
@echo off setlocal enabledelayedexpansion :start cls echo. echo SUPPORT TOOLS LOW COST echo. for /F %%a in ('ECHO prompt $E ^| cmd') do ( SET "ESC=%%a" ) set /p stcode=!ESC![0m INPUT STORE CODE:
if "%stcode%"=="" goto start ping -n 1 -w 1000 pth%stcode% >nul if errorlevel 1 ( echo. echo %stcode% is !ESC![31mOFFLINE!ESC![0m echo. if exist (%temp%!stcode!.txt) type %temp%!stcode!.txt echo. pause set stcode= goto start ) else ( echo. echo %stcode% is !ESC![32mONLINE!ESC![0m )
echo. osql -S pth!stcode! -U TRANSF -P FSNART -Q "set nocount on; use estore; select stcode as 'STORE CODE', short_name as 'STORE NAME', main_ipaddress as 'IP Server' from pospara; select LOCKNO, LOCKNAME, RCVNO, IPADDRESS from posterminal where status = 'a'" -w 1000 -o %temp%!stcode!.txt type %temp%!stocode!.txt echo.
pause set stcode= goto start
endlocal
- Assistant
- User
in case if ping to offline host, i waiting too long, any way to timeout for 2 second
- Assistant
Yes, you can adjust the timeout for the
pingcommand in your batch script to ensure it only waits for 2 seconds (2000 milliseconds) instead of the default settings. Eachpingcommand can be configured to send one packet and wait for a specified timeout. Here’s how you can modify your script for a 2-second timeout:@echo off setlocal enabledelayedexpansion :start cls echo. echo SUPPORT TOOLS LOW COST echo. REM Get escape character for coloring the output for /F %%a in ('ECHO prompt $E ^| cmd') do ( SET "ESC=%%a" ) REM Prompt for store code input set /p stcode=!ESC![0m INPUT STORE CODE: REM Check if the input is empty, if so, restart if "%stcode%"=="" goto start REM Check if the store is online by pinging with a 2-second timeout ping -n 1 -w 2000 pth%stcode% >nul if errorlevel 1 ( echo. echo %stcode% is !ESC![31mOFFLINE!ESC![0m echo. REM Display any stored information for the offline store if available if exist (%temp%\!stcode!.txt) type %temp%\!stcode!.txt echo. pause set stcode= goto start ) else ( echo. echo %stcode% is !ESC![32mONLINE!ESC![0m ) echo. REM Query the SQL server to get store details and save results to a temp file osql -S pth!stcode! -U TRANSF -P FSNART -Q "set nocount on; use estore; select stcode as 'STORE CODE', short_name as 'STORE NAME', main_ipaddress as 'IP Server' from pospara; select LOCKNO, LOCKNAME, RCVNO, IPADDRESS from posterminal where status = 'a'" -w 1000 -o %temp%\!stcode!.txt REM Display the results from the SQL query type %temp%\!stcode!.txt echo. pause set stcode= goto start endlocal