![]() |
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-23 16:04 |
47,812 topics / 349,917 posts / today 0 new / 48,273 members |
| DOS批处理 & 脚本技术(批处理室) » Please ask again, I can't answer this question now. Please provide other topics for me to answer. |
| Printable Version 1,827 / 10 |
| Floor1 sglxy | Posted 2005-10-29 20:50 |
| 中级用户 Posts 87 Credits 397 | |
|
Recently I wrote a batch program, but every time it reaches this part, something is wrong:
******************************* echo Which partition do you want to restore the system to (please enter the partition number or drive letter)?: (123456789 or DEFGHIJKL) set WHAT= what s for %%a in (D E F G H I J K L) do IF == goto _copy for %%b in (1 2 3 4 5 6 7 8 9) do IF == set HDRV=1:%%b ghost -clone,mode=pload,src=%CDROM%\sysbak.GHO:1,dst=%HDRV% -sure -rb goto to_BOOT :_copy for %%c in (C D E F G H I J K L) do IF == set HDRV=%WHAT% sys %HDRV%: copy /y a:\gho\*.*\ %HDRV% ************************************ Later, I found that the value in the variable %HDRV% is incorrect, it's empty. It seems these two sentences are wrong: for %%a in (D E F G H I J K L) do IF == goto _copy for %%b in (1 2 3 4 5 6 7 8 9) do IF == set HDRV=1:%%b Please brothers help me see where the problem is? Why? —————————————— Edited by willsort —————————————— Original title: Please brothers help me see where this batch is wrong. To facilitate users' browsing and moderators' management, please briefly describe its content or intention in the post title You can click the "Edit" button below the post to modify the title on the editing page and confirm it If no modification is made within three days, the moderator will modify it, and the author of this post will be deducted 4 points of points at the same time —————————————— Edited by willsort —————————————— [ Last edited by sglxy on 2005-11-1 at 23:51 ] |
|
| Floor2 sglxy | Posted 2005-10-29 22:44 |
| 中级用户 Posts 87 Credits 397 | |
|
Hello, moderators. Is anyone online? Please take a look for me. Thanks in advance.
|
|
| Floor3 sglxy | Posted 2005-10-30 19:51 |
| 中级用户 Posts 87 Credits 397 | |
|
What a pity, the experts are all not here!
|
|
| Floor4 JonePeng | Posted 2005-10-30 23:06 |
| 金牌会员 Posts 1,883 Credits 4,562 From 广东广州 | |
|
Try to change [%WHAT%] to [%%WHAT%%]
|
|
| Floor5 本是 | Posted 2005-10-31 12:03 |
| 银牌会员 Posts 790 Credits 2,227 | |
|
Re sglxy:
There is a problem with the usage of what in your case. It should not be what S, but what C "prompt message" character list. The C command will automatically limit the range of input characters, so there is no need to perform IF tests anymore. Modify as follows: ******************************* set WHAT= what C "Which partition do you want to restore the system to (please enter the partition number or drive letter)? (123456789 or DEFGHIJKL):" 123456789DEFGHIJKL for %%a in (D E F G H I J K L) do goto _copy for %%b in (1 2 3 4 5 6 7 8 9) do set HDRV=%%b ghost -clone,mode=pload,src=%CDROM%\sysbak.GHO:1,dst=1:%HDRV% -sure -rb goto to_BOOT :_copy for %%c in (C D E F G H I J K L) do set HDRV=%WHAT% sys %HDRV%: copy /y a:\gho\*.*\ %HDRV% ******************************* [ Last edited by 本是 on 2005-10-31 at 12:44 ] |
|
| Floor6 sglxy | Posted 2005-10-31 12:56 |
| 中级用户 Posts 87 Credits 397 | |
|
Thanks to brother "Ben Shi" for the reply, but I still have a question, please see:
for %%a in (D E F G H I J K L) do goto _copy Is the syntax a bit awkward after such a change? |
|
| Floor7 willsort | Posted 2005-10-31 14:16 |
| 元老会员 Posts 1,512 Credits 4,432 | |
|
Re sglxy & Ben Shi:
Brother sglxy's original code will cause problems, which should be related to the %what% variable. As for the correctness of the usage of what s, since I haven't been in contact with this tool for a long time, I can't comment; but I guess what s is for accepting string input, so it should be able to achieve your intention. for %%a in (D E F G H I J K L) do IF [%%a]==[%WHAT%] goto _copy not only "limits the range of input characters", but also sorts the input characters. If it is a letter, it will goto _copy; if it is a number, it will ghost. Therefore, the if segment should not be omitted. |
|
| Floor8 本是 | Posted 2005-10-31 16:36 |
| 银牌会员 Posts 790 Credits 2,227 | |
|
What Willsort said, "for %%a in (D E F G H I J K L) do IF == goto _copy not only 'limits the range of input characters', but also sorts the input characters. If it is a letter, it goes to _copy; if it is a digit, it goes to ghost. Therefore, the if fragment should not be omitted." is very correct.
What command C can limit the range of input characters, while command S cannot. This is very important for this.BAT. The problem here is probably due to the setting rules of environment variables in NT-series operating systems being different from those in WIN9X! [ Last edited by 本是 on 2005-10-31 at 16:38 ] |
|
| Floor9 sglxy | Posted 2005-10-31 18:27 |
| 中级用户 Posts 87 Credits 397 | |
|
Thank you very much to the two experts for your guidance. This batch script is a part of the automatic recovery function for hiding partitions that I made. The method is to first: run gdisk to display partition information, and then manually enter which partition to operate on. Then the what s command passes the input key value to the variable %WHAT% in the for %%a in (D E F G H I J K L) do IF == goto _copy for judgment. If it is one of them, it means that the partition is not hidden (the partition will not have a drive letter after being hidden), and then I can install some personalized recovery functions on this partition. But this method that I thought was foolproof偏偏 doesn't get the expected result. Now I don't understand why the judgment sentence for %%a in (D E F G H I J K L) do IF == goto _copy doesn't work. I think its syntax should be correct.
In addition, I would like to ask the "Ben Shi" brother, in the case of needing to limit the input character range, how to write the "what c" command (syntax)? What is the resulting variable form, and how should this variable be operated? Please give an example, thank you. [ Last edited by sglxy on 2005-10-31 at 18:38 ] |
|
| Floor10 Archimonde | Posted 2005-11-01 13:37 |
| 新手上路 Posts 2 Credits 3 | |
|
I have a personal programming habit, which is to display one by one the parameters it calls in front of the erroneous statement. I wonder if you have tried it
|
|
| Floor11 willsort | Posted 2005-11-02 12:55 |
| 元老会员 Posts 1,512 Credits 4,432 | |
|
Re sglxy:
The usage of what c was already given by brother in floor 5. The last parameter 123456789DEFGHIJKL is the one that limits its input range. For other usages of what, it should not be difficult to understand by looking at its command line help. The line for %%a in (D E F G H I J K L) do IF [%%a]==[%WHAT%] goto _copy has no grammatical errors, but it is not guaranteed to have no usage errors. If the variable value of %WHAT% has spaces before or after, then you will never make the if judgment hold. So you should follow Archimonde's suggestion, add a line echo what result=[%what%] before the for statement to check if its output result is normal. If this result is normal, then the problem may be in other statements. |
|
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |