![]() |
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-09-14 17:22 |
47,812 topics / 349,917 posts / today 0 new / 48,268 members |
| DOS批处理 & 脚本技术(批处理室) » [Original] Scheduled Task Mini Program [Update on 06.12] |
| Printable Version 4,374 / 19 |
| Floor1 jastyg | Posted 2006-06-08 19:20 |
| 中级用户 Posts 82 Credits 219 | |
|
I haven't learned DOS myself. I'm afraid this can be attributed to the relatively late time I got in touch with computers. Fortunately, I found this great place. How happy I was~~~ And I feel that as long as I come here, I will definitely gain something!
First of all, I've been soaking in the forum for more than half a year. My level is very low, and I approach any problem with a learning attitude. But fortunately, the atmosphere of the whole forum is very good. In addition to the active attitude of the forum members, more importantly, there are a group of enthusiastic and highly skilled moderators here. They can be said to be very good teachers for us. Here, I would like to express my gratitude to the friends who have helped me. I spent 2 days writing this small program. I mainly wanted to use what I've learned here in one go. Of course, it's a relatively low-level program. I hope you don't laugh at it and give me support. Please let me know if there are any improper or incorrect places in my writing. I'm very willing to accept suggestions. Change time: 2006.6.9 10:00 Spent some time in the morning adding comments, which is equivalent to checking the existing problems again by myself. Sure enough, I found a few problems. :P, the attachment hasn't been updated, and there are several problems with upper and lower cases Change time 2006.6.12 13:00, added inspection of time and date After writing it on the first day, I felt everything was fine. But after several tests by myself, I found many problems. Now I've changed all the problems I know. Currently, I feel very good (of course, the teachers will definitely find many flaws when they see it, hehe) There is the one I added a shell to in the attachment, which can be used directly. It feels comparable to the AT command. [ Last edited by jastyg on 2006-6-12 at 16:09 ] Attachments etime.rar (63.43 KiB) |
|
| Floor2 namejm | Posted 2006-06-08 20:17 |
| 荣誉版主 Posts 1,737 Credits 5,226 From 成都 | |
|
I copied and ran your code for a trial run, and initially found the following problems:
1. Each step of operation only has input prompts, but no functional explanations of the input, making it unclear what operation will be executed after input; it is suggested to provide functional prompts for each step of operation; 2. I don't know what command to input to view your help content; even if I input the specified commands such as /? /help, other functions are run; it is suggested to modify the code; 3. There is no need to use @ again to hide the commands after @echo off; it is suggested to delete the duplicate @ to streamline the code; 4. In the code, the naming of labels is sometimes in English and sometimes in pinyin, which is relatively chaotic; the functions of each part are even sometimes represented by numbers, making it difficult to immediately understand what function the content under the label is; it is suggested to unify the naming of labels, preferably so that the name can indicate the meaning; 5. There is no error detection in the input part, and if the input is wrong, the program may have accidents during operation; it is suggested to perform error detection on the input part; 6. When setting variables, variables with specific meanings such as rem, tmp are used, and I personally think it may have an impact on the CMD environment (no further verification has been done, and authoritative conclusions are awaited from various experts); it is suggested to replace them with other characters; Hehe, I just talked a lot about the shortcomings of your code, hope you don't mind. I am currently improving a file backup script program, and hope you can pay attention to it. Part of the code will be helpful for you to improve this script, and at the same time, I hope you can give some suggestions on my script. The following is the address of my script in this forum: File Backup Tool: http://www.cn-dos.net/forum/viewthread.php?tid=20747&fpage=0&highlight=&page=1 [ Last edited by namejm on 2006-6-8 at 20:30 ] |
|
| Floor3 jastyg | Posted 2006-06-08 20:43 |
| 中级用户 Posts 82 Credits 219 | |
|
1. Each step of the operation only has input prompts, but no functional explanations for the input, making it unclear what operation will be performed after input; it is suggested to provide functional prompts for each step of the operation;
I think this is not necessary to explain in detail. It should be okay to just follow the guide. 2. Don't know what command to enter to view your help content; even if entering the specified commands like /? /help, other functions are run; it is suggested to modify the code; Here, under XP/2K3, entering etime /? or etime /h can be viewed. I don't know what system you have? 2000 has no environment, so I can't test it. 3. The @echo off command doesn't need to use @ again to hide the subsequent commands; it is suggested to delete the duplicate @ to streamline the code; I am ignorant and didn't find the excess, please point it out clearly, thank you 4. In the code, the labeling is sometimes in English and sometimes in pinyin, which is relatively chaotic; the functions of each part are even sometimes represented by numbers, making it difficult to immediately understand what function is under this label; it is suggested to unify the labeling, preferably so that the meaning can be known from the name; This is because I didn't think very comprehensively when designing it at that time, resulting in many problems during testing, and I had to make do. Hehe 5. There is no error detection in the input part, and if the input is wrong, the program may have accidents during operation; it is suggested to perform error detection on the input part; Simple input detection has been done. I think when asking you to enter the day, the most common is to enter, for example, on the 7th, generally 07 OR 7. I can't imagine that the user would enter 70? 6. When setting variables, rem, tmp and other variables with specific meanings are used. Personally, I think it will affect the CMD environment (no further verification has been done, waiting for experts to give authoritative conclusions), it is suggested to replace them with other characters; This is indeed a defect. Thank you for clearly pointing it out. But fortunately, my current test hasn't reached the point of affecting use yet Thank you for your valuable suggestions. Many problems are inevitable during the learning process, and I will accept your suggestions. |
|
| Floor4 namejm | Posted 2006-06-08 21:48 |
| 荣誉版主 Posts 1,737 Credits 5,226 From 成都 | |
|
Re jastyg:
Still pondering how your script works : ) According to the general habit of people using bat programs, usually they double-click the script to run it. No one would open the cmd window first and then enter the full path of the bat program to run it. So, in the first interface that opens after double-clicking the bat, there should have the function introduction of the program, or prompt to enter a certain command or character to view the help content of the script. It is precisely because of this habit issue that when double-clicking the script to run, directly entering /? to view the help of your script results in irrelevant help content, almost making me doubt if my CMD is malfunctioning : ) In the line @color 1f after @echo off, the @ can be removed. Regarding the error detection section, my opinion is like this: If when entering, you accidentally just press Enter, that is, when the input is empty, the operation will have an accident - you can't guarantee that others will input correctly all the time. There are other situations of input errors, so please consider more for careless users. Another situation: In your code, the time entry is very problematic without explanation. Exactly, should you enter the integer point of time, or the format with colons? Should it be precise to seconds?... Because in batch processing, rem is for comments, and %tmp% refers to the temporary file directory. Setting them as variables is okay in your current script, but it is still recommended not to set batch processing commands or system environment variables as variables, so as to avoid mistakes when getting confused when referencing with a large amount of code. Good code writing habits are a great guarantee for writing correct code, what do you think? If you want to pursue perfection, there are many places worth improving: for example, consider removing the drop-down bar of the CMD window to prevent novices from getting lost in the content after randomly pulling it. Hehe, always picking on your flaws, hope you don't mind again. |
|
| Floor5 jastyg | Posted 2006-06-08 22:08 |
| 中级用户 Posts 82 Credits 219 | |
|
re: namejm
Brother's statement makes a lot of sense. Maybe it's because I haven't written a program myself, and I really didn't think through things very comprehensively. In the line @color 1f, the @ was a momentary oversight of mine. Because there were many problems during the program testing, so I directly added @echo off in the first line for easier testing. Regarding the empty input, I have already thought about how to handle it, thank you for the reminder. The instructions really should be added at the beginning of the program for clearer understanding. The time format is like 20:05. Brother's suggestions to me have benefited me a lot. My original intention was also to release what I wrote for everyone to see, and what I hope to get is to have my deficiencies pointed out. I'm really grateful to you. I just read brother's post, and I admire your patience and level. I didn't finish reading your post. For one thing, I don't have patience, and for another, I don't understand many places. Please forgive me~~~~ |
|
| Floor6 namejm | Posted 2006-06-08 23:05 |
| 荣誉版主 Posts 1,737 Credits 5,226 From 成都 | |
|
Regarding my level, actually you can tell from my registration time; also, my current job is far removed from the computer field, and it's hard for outsiders to connect the two. It's just that I'm very interested in computers, so I've been lurking in the forum :) I've learned a lot here, and I really thank the many experts here. Hehe, it seems I've strayed a bit.
Hehe, I'm going to pick on your faults again ha—It seems like I'm specifically picking on you, don't throw bricks at me. The two lines goto kaishi and :kaishi, since they are right next to each other, according to the execution order of bat commands, which is top-to-bottom execution (except for jumps), so the goto kaishi line can be omitted; In the line if "%1"=="0" set d=0&set riqi=0& goto t, the set d=0 and set riqi=0 can be omitted. In CMD, there's no need to initialize variable values (hehe, is there such a saying as "initialization" in CMD? I'm not very懂 either, I'll call it that for now). Of course, doing this also doesn't cause errors in running;(Later, referring to other posts, I found that this statement is wrong. Setting the initial value to 0 is necessary) What's the role of +0 in the line set /a tmp=%date:~8,3%+0 >nul? What's the meaning of the error code 9167 in the line if errorlevel 9167 goto tmp1? Is it a statement to judge the operating system version? I don't understand very well, please explain; The几句 echo %date:~8,2% >tem.txt find "08" tem.txt >nul if not errorlevel 1 set riqi=8&goto tmp3 are not very understandable: Why look for the character "08"? What's the role? After each input is completed, it's recommended to use the cls command to clear the screen, don't let the previous input remain on the screen. Also, I feel that when you write the code, the logic isn't very smooth. It's recommended to string the code in the following order: first write the code for each step when input is correct together, then put the code with branch flows together, and finally put all the error detection codes together. Each section of code labeled with a label should preferably have comments to indicate the function of this section, and you can consider adding comments where important. If you do this, it will make it very easy for people to see the logical structure of the code you wrote. It's not only convenient for you to quickly find the position when improving the code later, but also makes it easy for others to see where the errors are. Due to my limited level, I've only raised the above few questions for now. There are more areas that can be improved, and everyone needs to discover them. [ Last edited by namejm on 2006-6-9 at 00:36 ] |
|
| Floor7 jastyg | Posted 2006-06-08 23:34 |
| 中级用户 Posts 82 Credits 219 | |
|
re: namejm
According to your hint, I have made some modifications. It's really tiring to make large-scale changes, heh heh! What's the function of +0 in the sentence set /a tmp=%date:~8,3%+0 >nul? Actually, I have no choice. You should carefully look at SET/? and you will get 08, 09 are invalid numbers because 8 and 9 are not valid octal digits. So running the above code will cause an error. By echo %errorlevel % we get errorlevel =9167. Because 8 and 9 are invalid, so if the input date is 8 or 9, my program can't be correct (PS: yesterday was the 7th, I tested it well, but today it's not working, and then I found this problem, and it's okay except for 8 and 9) echo %date:~8,2% >tem.txt find "08" tem.txt >nul if not errorlevel 1 set riqi=8&goto tmp3 By exporting the characters showing the day in the specified date to TEM.TXT and then searching, if there is 8, set %riqi%=8 (that is, the 8th), and similarly get the 9th. Because I determine whether the values are consistent by if "%riqi%%time:~0,5%"=="%d%%t%", so I go to run. Indeed, the logic is much worse, please forgive me, heh heh. It's enough to be able to use it~~~. With this experience, it should be much better in the future~~ Thanks for your patient guidance It's getting late, go to bed early. Looking forward to your reply tomorrow~~~ PS: I also found that there are still some problems and deficiencies. I want to see if I can solve them tomorrow, such as users mistakenly entering special symbols, etc. I hope you can give good ideas. [ Last edited by jastyg on 2006-6-8 at 23:40 ] |
|
| Floor8 namejm | Posted 2006-06-09 00:00 |
| 荣誉版主 Posts 1,737 Credits 5,226 From 成都 | |
|
Compared with the more than 700 lines of code in my file backup tool (but many are rem and echo statements, which is an exaggerated statement I made on purpose), your code with more than 100 lines is considered small. But I can still quickly find out where the problem is, which is precisely due to the fact that I sorted out the logical order relatively well at the very beginning (I don't dare to say it's the best logical order). I hope you can also come up with an order that is convenient for your own modification.
Regarding input error detection, it has been discussed a lot in my post about the file backup tool. Just take your time to read it and you will understand. Here's a suggestion for you: when writing code, try to generate as few temporary files as possible. If you have to generate temporary files, think more about whether you can use the for statement and connectors such as &, &&, |, and || to avoid temporary files. I still can't fully understand your code, but my intuition tells me that there should be a more concise way to handle the numbers 8 and 9 in the statement set /a tmp=%date:~8,3%+0 >nul. Hehe, ask Boss willsort, he should have a way. |
|
| Floor9 namejm | Posted 2006-06-09 00:55 |
| 荣誉版主 Posts 1,737 Credits 5,226 From 成都 | |
|
to jastyg:
The moderator has marked your post with a red line. You need to work hard and strive to get it pinned or made an essence. ???? I'm going to sleep now~~~~~ |
|
| Floor10 willsort | Posted 2006-06-09 02:13 |
| 元老会员 Posts 1,512 Credits 4,432 | |
|
Re jastyg:
First of all, "original" code is worthy of appreciation and encouragement, which is the decisive consideration for me to highlight this topic with a red underline. Secondly, there are many technical details in this topic that can be discussed, so it has the potential to become an essence topic; of course, before that, we first need to initially improve the code in the topic, that is, the framework logic improvement mentioned by Brother namejm, mainly including the relatively independent function of each module, clear and easy-to-understand tag names, and appropriate blank lines as spacing. Again, it is suggested that your code release method refer to Brother namejm's original topic. The new code will be continuously updated in the first post of the topic, and the changed version number and update date will be marked in the topic title. In addition, it is suggested that when you repost the code, use [code] and [/code] before and after the code, so as to prevent some special characters in the code from being escaped, which is convenient for browsing and copying, and at the same time highlight the particularity of the code. Finally, regarding the 08/09 problem handed over to me by Brother namejm, this is my consideration. The reason why 08/09 is recognized as an octal number is because the set/a command is used, and I have observed all the set/a statements in the code, which only add zero to the date value, and I can't see what practical meaning it has. Maybe you want to realize the conversion of the date string to an integer value, but this is not needed and difficult to realize in batch processing. All command line programs that can handle integers will automatically convert the string number to an integer value by themselves, because this is an inherent convention in the command line environment. Of course, the 08/09 problem can be solved more simply. If you really need to perform set/a operation on the date value, I can provide corresponding solutions. [[i] Last edited by willsort on 2006-6-9 at 02:18 [/i]] |
|
| Floor11 jastyg | Posted 2006-06-09 08:51 |
| 中级用户 Posts 82 Credits 219 | |
|
re: namejm
Due to the limitations of my ability, there are actually things I want to do but can't. As you said, using statements like FOR, but I don't have an in-depth understanding of this aspect. Of course, I have also read quite a few posts on this topic, and I really find it a bit deep, heh heh. Take it slow~~ re: willsort First of all, thank you, moderator, for helping me many times. Regarding SET/A, this is how I understand and do it. Because when I get the date value, there is such a problem. For example, the order number is from the 1st to the 9th, but I have to get a 2-character value, otherwise it will be wrong when it comes to the even-numbered days. That is, for example, if it is the 7th, the value obtained is: 07. If the time I specified is entered as 7, then the two sides are not equal, and the statement will execute incorrectly. So I make the current date +0 to make it a ten-digit number to remove the space. Similarly, I have also processed the user-entered date to remove the ten-digit space, so that the statement can run smoothly. Of course, I am very willing for the moderator to give a better solution. I will try to take some time to add comments to the above (heh heh, I myself find it a bit confusing, if it weren't written by myself, I really wouldn't have the patience to read it) PS: The World Cup is here, another torturous day~~~ [ Last edited by jastyg on 2006-6-9 at 21:40 ] |
|
| Floor12 jastyg | Posted 2006-06-09 11:32 |
| 中级用户 Posts 82 Credits 219 | |
|
Regarding the verification of illegal characters, I came up with a method, but it feels a bit cumbersome. Let me post it first:
@echo off set /p da= for %%i in (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,?,h,H,/?,/h,/H) do if "%da%"=="%%i" goto ok goto warng :ok echo ok goto exit :warng echo Error :exit This can indeed detect the date, but what about the verification of the time format? |
|
| Floor13 jastyg | Posted 2006-06-09 11:55 |
| 中级用户 Posts 82 Credits 219 | |
|
For the detection of time, I thought of a stupid method
Check the user-entered time in segments for the same date. I wonder if there is a better way? |
|
| Floor14 willsort | Posted 2006-06-09 17:58 |
| 元老会员 Posts 1,512 Credits 4,432 | |
|
Re jastyg:
Understood the intention of the brother using set/a from the reply on floor 11, which is to remove the possible leading zeros in the date value to have a unified format for easy comparison. Well, this problem can be viewed from two aspects: 1. Ensure all dates have possible leading zeros so that they can be compared. Because the system date usually has possible leading zeros, so we usually only need to handle the user-input date variable. The specific plan to be adopted is to pad first and then intercept, for example: set today=%date:~8,2% set /p day=Please enter the date: set day=0%day% set day=%day:~-2% echo Input date: %day%; System date: %today%; 2. Ensure all dates do not have possible leading zeros so that they can also be compared. Because the system date usually has possible leading zeros, so we need to handle both the user-input date value and the system date value. Here we use the method of adding 10000 or 1000 first and then taking the remainder. For example set today=%date:~8,2% set /p day=Please enter the date: set /a today=100%today% %% 100, day=100%day% %% 100 echo Input date: %day%; System date: %today%; |
|
| Floor15 namejm | Posted 2006-06-09 19:14 |
| 荣誉版主 Posts 1,737 Credits 5,226 From 成都 | |
|
The boss really has many ways, quite clever.
To jastyg: Actually, there's no need to comment so much content. Too many comments will反而 have a sense of redundancy. Moreover, when posting code, you can use this method to ensure that certain characters are not converted by the webpage and also facilitate others to copy your code for testing purposes: first input [code] and [/code], then paste the code between them, and then post it. Actually, it's quite simple. It's best to use the "Reply" mode to edit, as there are more formats available; the "Quick Reply to Topic" mode has almost no formats available. Those familiar with webpage code can manually input code here to edit. If you are not familiar, it is recommended to still use the "Reply" mode to do it. [[i] Last edited by namejm on 2006-6-9 at 19:16 [/i]] |
|
| 1 2 Next |
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |