China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-02 15:34
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » How to open the document every 5 seconds and automatically close the document after 2 seconds View 1,595 Replies 5
Original Poster Posted 2006-11-17 05:01 ·  中国 广东 广州 花都区 电信
初级用户
★★
Credits 197
Posts 77
Joined 2006-09-19 14:02
19-year member
UID 63074
Gender Male
Status Offline
@echo off
set n=1
:start
cls
for /f "tokens=1,2" %%i in ('arp -a^|findstr /c:" 192.168.0.251"') do echo %n% times %%i %%j >>temp.txt
for /f "tokens=1,2" %%i in ('arp -a^|findstr /c:" 192.168.0.251"') do echo %n% times %%i %%j
set /a n=%n%+1
rem Remove the limit of showing 20 times, and open temp.txt every 5 seconds
for /l %%a in (0,1,9999) do (
start temp.txt
ping -n 2 127.1 >nul
timeout /t 5 /nobreak >nul
taskkill /f /im notepad.exe >nul 2>nul
)
goto start

The part where it shows the number of times in temp.txt is controlled by itself.. It can only show 20 times. Can it not limit the number of times to open temp.txt, and loop to open temp.txt every 5 seconds? Also, open temp.txt every 5 seconds and automatically close the opened temp.txt after 2 seconds?
Floor 2 Posted 2006-11-23 03:13
中级用户
★★
DOS之日
Credits 337
Posts 161
Joined 2006-11-04 05:27
19-year member
UID 69523
Gender Male
Status Offline
for /f %%h in (`echo hxuan`) do for /f %%x in (`echo hxuan`) do if %%h==%%x nul
Floor 3 Posted 2006-11-23 23:38 ·  中国 甘肃 兰州 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
Open temp.txt every 5 seconds, display it for 2 seconds and then automatically close the opened temp.txt

start and taskkill
Floor 4 Posted 2006-11-24 02:47 ·  中国 北京 联通
金牌会员
★★★★
Credits 2,902
Posts 1,147
Joined 2006-09-21 12:00
19-year member
UID 63324
Gender Male
Status Offline
sendMsg.cmd code is as follows:


@echo %dbg% off
cls

echo.
echo Debug status: Execute set dbg=on on the command line to display the execution echo process
echo Turn off debugging: Execute set dbg= on the command line to turn off echo and enter normal operation mode
echo Exit execution: If you need to terminate the operation during execution, press the Q key to exit
echo Simple test: arp -a lists the IPs, fill this IP into set ".IP=fill here" for experiment
echo.

:Redtek 2006
:: Set the IP address to be ARP operated
:: set ".IP=192.168.0.12"
set ".IP= 192.168.0.251"

:: Set the message receiver: it is the login name of the user's windows
set ".sessionName=%username%"

:: Set the temporary file name for displaying messages
set ".saveFile=temp.txt"

:: Set the time to display the message: seconds
set ".viewTime=2"

:: Set the time to display the command of the next message window: seconds
set ".DoNextCmd=5"

:: Set the number of times the message window is displayed
set ".loopRunNum=20"

:: Initialize the temporary file in append mode to prevent unexpected errors
echo.>>"%.saveFile%"

:start
set /a ".loopRunNum-=1"
if %.loopRunNum%==0 goto :end

for /f "tokens=1,2" %%i in ('arp -a^|findstr /c:"%.IP%"') do ( echo %%i %%j>>"%.saveFile%" )

msg "%.sessionName%" <"%.saveFile%" /time:%.viewTime% /w
choice /T %.DoNextCmd% /C rq /d r /n>nul
if %errorlevel%==2 goto :end
goto :start

:end
:: Clear the used variables
:: Adding a unified symbol "." in front of the used variables is to facilitate variable cancellation :)
for /f "delims==" %%i in ('set .') do set "%%i="
set "dbg="




In the ":Redtek 2006" label code segment, you can change the initial variables according to your own needs.


Principle: Use the MSG message sending system built into the Windows system to complete the message display tool.
    The /w parameter of MSG has the function of "blocking execution state" to execute and display the current window. When executing, the system is in a waiting state and exits after completion.

    The /TIME parameter of MSG has a time delay function for waiting for the receiver to confirm the message, that is, unless the user actively ends the window, the message will end after the specified n seconds.
    In this way, the method of forcibly killing the process to try to close the message display window is replaced.

    At the same time, MSG can send the specified message to any computer in the local area network, whether it is broadcasting or specifying the receiver, it can be achieved.

    If you use the Ping -n ....<nul command to indirectly achieve the effect of "delay", the CPU will be in a high load state, even up to 90%.
    So CHOICE is used to achieve the effect of waiting for delay. After testing, its CPU peak is about 0-2%.
    And the function of CHOICE to get the user's selected value can achieve terminating the code operation by pressing the specified key, which is convenient for the user to exit safely during execution.

    When executing ARP, its CPU test peak is about 2-13%, which has little impact on the system.


    The statement for /f "delims==" %%i in ('set .') do set "%%i=" is set to clear the used variables.
    The variables used in the code all start with a ".", so when I finish using them, just one For is enough, no need to list them one by one and then delete them.
    This is using SET . When this operation is performed, the system will display all variables starting with ".", and a for will naturally find and "introduce" them all, and then assign an "empty" value to clear the operation.



) Another: If you can't find the CHOICE.EXE file in the Chinese version of Windows XP system, this file is compressed into the attachment of this post together with this code. Friends who need it can download it conveniently : )
Attachments
sendMsg.rar (17.47 KiB, Credits to download 1 pts, Downloads: 22)
    Redtek,一个永远在网上流浪的人……

_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._
Floor 5 Posted 2006-11-25 10:13 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline
```
@echo off
set/a n=1
:start
cls
for /f "tokens=1,2" %%i in ('arp -a^|findstr /c:" 192.168.0.251"') do (
echo %n% 次 %%i %%j >>temp.txt
echo %n% 次 %%i %%j
)
set/a n+=1
set n_=
set/a n_=%n%%%5
if %n_% equ 0 (
start "" temp.txt >NUL 2>NUL
ping -n 3 127.1 >nul 2>NUL
taskkill /fi "WINDOWTITLE EQ temp.txt - 记事本" >nul 2>nul
REM Because the content in temp.txt is too much, and the temp.txt file is only opened for two seconds and then closed, so it is recommended to clear the content inside first.
REM The next step is to clear, if not needed, you can add REM in front.
cd.>temp.txt)
ping -n 2 127.1>nul
goto start
```
Recent Ratings for This Post ( 2 in total) Click for details
RaterScoreTime
redtek +3 2006-11-25 10:22
lfun +1 2007-12-20 20:38
Floor 6 Posted 2006-11-26 20:34 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline

Thanks a lot for Brother Redtek's encouragement many times~
Forum Jump: