![]() |
China DOS Union-- Unite DOS · Advance DOS · Grow DOS --Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum |
| Guest | Log in | Register | Members | Search | China DOS Union |
|
中国DOS联盟论坛 The time now is 2026-08-09 16:01 |
47,811 topics / 349,896 posts / today 1 new / 48,254 members |
| DOS批处理 & 脚本技术(批处理室) » Execute a batch file when the value read in real time from a txt file meets a condition? |
| Printable Version 1,058 / 12 |
| Floor1 qwertl | Posted 2008-09-02 20:33 |
| 中级用户 Posts 243 Credits 461 | |
|
After getting the content value of a txt file in real time and calculating it, if it meets the condition then execute another batch program? Please advise.
Storage directory:d:\record txt filenames:Ter2008Y4M16D12h.txt Ter2008Y4M16D13h.txt Ter2008Y4M16D14h.txt Ter2008Y4M16D15h.txt : : one such file is generated every hour. The txt format is: ( one line is generated every second as a record, the time interval can be specified, for example one line every 3 minutes, and each time I need to take the value in the last column of the latest record.) 682 2008-4-16 15:00:00 26.75 683 2008-4-16 15:00:01 26.75 684 2008-4-16 15:00:02 26.75 685 2008-4-16 15:00:03 27.25 686 2008-4-16 15:00:04 27.25 687 2008-4-16 15:00:05 27 688 2008-4-16 15:00:06 27 689 2008-4-16 15:00:07 27.25 690 2008-4-16 15:00:08 26.75 691 2008-4-16 15:00:09 27.5 692 2008-4-16 15:00:10 27.5 693 2008-4-16 15:00:12 26.75 694 2008-4-16 15:00:13 27.5 695 2008-4-16 15:00:14 27.25 696 2008-4-16 15:00:15 27 697 2008-4-16 15:00:16 27 698 2008-4-16 15:00:17 27.25 699 2008-4-16 15:00:18 27.25 700 2008-4-16 15:00:19 27.5 701 2008-4-16 15:00:20 27.25 702 2008-4-16 15:00:21 27.25 703 2008-4-16 15:00:22 27.25 Now what I need is: can a program monitor in real time (or every 3 minutes) and get the value in the last column of the newest txt file, and if the value is greater than 30 then automatically execute another batch program; and every day automatically compress all txt files generated on the previous day under d:\record into another directory, stored as a compressed file named with the previous date. For example: d:\rardata\%date%-1.rar [ Last edited by qwertl on 2008-9-2 at 08:54 PM ] |
|
| Floor2 HAT | Posted 2008-09-02 20:58 |
| 版主 Posts 5,017 Credits 9,023 | |
| Floor3 qwertl | Posted 2008-09-02 21:03 |
| 中级用户 Posts 243 Credits 461 | |
|
Thanks HAT. Using goto solved it, amazing.
![]() Also, every day automatically compress all txt files generated on the previous day under d:\record into another directory, stored as a compressed file named with the previous date. For example: d:\rardata\%date%-1.rar How should that be done? [ Last edited by qwertl on 2008-9-2 at 09:19 PM ] |
|
| Floor4 HAT | Posted 2008-09-02 21:47 |
| 版主 Posts 5,017 Credits 9,023 | |
| Floor5 qwertl | Posted 2008-09-02 21:59 |
| 中级用户 Posts 243 Credits 461 | |
|
This is workable, but the txt filenames are:Ter2008Y4M16D12h.txt
Ter2008Y4M16D13h.txt Ter2008Y4M16D14h.txt Ter2008Y4M16D15h.txt : one such file is generated every hour. If the txt gets one line of record every second, won't that also take quite a bit of CPU and memory resources? Is it possible that whenever a new txt file is generated, the txt files generated earlier in the meantime are automatically moved to another directory? That way it probably won't keep reprocessing lots of outdated values. I already learned how to do the compression problem from the previous post, though I still need to study a lot of commands before I can understand them. Really thank you! [ Last edited by qwertl on 2008-9-2 at 10:04 PM ] |
|
| Floor6 HAT | Posted 2008-09-02 22:12 |
| 版主 Posts 5,017 Credits 9,023 | |
|
Are these text files generated by a batch file? If so, just add a move in that batch file, right?
|
|
| Floor7 qwertl | Posted 2008-09-02 22:18 |
| 中级用户 Posts 243 Credits 461 | |
|
The text files are not generated by a batch file, they are data generated in a fixed format by an rs232 device, so I can't control that part, but the number of records in each file can be set by making the time interval a bit longer,
for /f "tokens=*" %%a in ('dir /s /b /a-d /o-d"%SrcDir%"') do ( Can this specify that only the first line's txt is passed to %%a? If so, then it would be enough to process only the newest generated txt file. If it can't specify only the first line, then is it possible to keep the first line's TXT file and move all the other TXT files to another directory first, and then execute the code in post #2. [ Last edited by qwertl on 2008-9-2 at 10:41 PM ] |
|
| Floor8 HAT | Posted 2008-09-02 22:55 |
| 版主 Posts 5,017 Credits 9,023 | |
|
Because of the existence of the goto statement, shouldn't what follows only process the first line's txt, that is, only process the newest generated txt file
|
|
| Floor9 HAT | Posted 2008-09-02 23:01 |
| 版主 Posts 5,017 Credits 9,023 | |
|
Would this make it a little clearer:
|
|
| Floor10 qwertl | Posted 2008-09-02 23:07 |
| 中级用户 Posts 243 Credits 461 | |
|
C:\>set SrcDir=C:\test
C:\>dir /b /a-d /o-d "C:\test\*.txt TEMPer2008Y3M30D9h.txt TEMPer2008Y4M16D15h.txt TEMPer2008Y3M28D15h.txt Running the code from post #9, it keeps looping with the message system cannot find the file TEMPer2008Y3M30D9h.txt. Records in the file c:\test\TEMPer2008Y3M30D9h.txt: 1 2008-3-30 9:19:25 0 2 2008-3-30 9:19:26 0 3 2008-3-30 9:19:27 0 4 2008-3-30 9:19:28 0 5 2008-3-30 9:19:29 0 6 2008-3-30 9:19:30 31 7 2008-3-30 9:22:32 -13.25 8 2008-3-30 9:22:32 -13.25 ____________________________________________________________ C:\>usbt C:\>set SrcDir=C:\test C:\>for /F "tokens=*" %a in ('dir /b /a-d /o-d "C:\test\*.txt"') do ( set NewFile=%a goto :next ) C:\>( set NewFile=TEMPer2008Y3M30D9h.txt goto :next ) C:\>for /F "usebackq tokens=4 delims=. " %b in ("TEMPer2008Y3M30D9h.txt") do (if %b GTR 30 ( echo start c:\12.bat ping -n 10 127.1 1>nul goto :begin ) ) The system cannot find the file TEMPer2008Y3M30D9h.txt. C:\>ping -n 10 127.1 1>nul C:\>goto :begin C:\>for /F "tokens=*" %a in ('dir /b /a-d /o-d "C:\test\*.txt"') do ( set NewFile=%a goto :next ) C:\>( set NewFile=TEMPer2008Y3M30D9h.txt goto :next ) C:\>for /F "usebackq tokens=4 delims=. " %b in ("TEMPer2008Y3M30D9h.txt") do (if %b GTR 30 ( echo start c:\12.bat ping -n 10 127.1 1>nul goto :begin ) ) The system cannot find the file TEMPer2008Y3M30D9h.txt. C:\>ping -n 10 127.1 1>nul ^CTerminate batch job (Y/N)? [ Last edited by qwertl on 2008-9-2 at 11:46 PM ] |
|
| Floor11 HAT | Posted 2008-09-02 23:53 |
| 版主 Posts 5,017 Credits 9,023 | |
|
The second for should use an absolute path
|
|
| Floor12 qwertl | Posted 2008-09-03 00:29 |
| 中级用户 Posts 243 Credits 461 | |
|
It works now, awesome.
|
|
| Floor13 keguanglidos | Posted 2008-09-03 04:37 |
| 新手上路 Posts 9 Credits 18 | |
|
So batch files can be used like this too, learned something, thanks
|
|
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |