|
sglxy
中级用户
   MS-DOS爱好者
积分 397
发帖 87
注册 2002-12-15
状态 离线
|
『楼 主』:
请问在这个批处理中为何%WHAT%的值无法正确传给其他变量?
使用 LLM 解释/回答一下
最近我写了一个批处理程序,但是每执行到这一段就不对了:
*******************************
echo 你要恢复系统到哪一个分区(请输入分区号或盘符)?(123456789或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%
************************************
后来才发现变量%HDRV%中的值不对,是空的。好象是这两句有错:
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
请兄弟们帮我看看到底错在那里?为什么?
—————————————— Edited by willsort ——————————————
原标题:请兄弟们帮我看看到这个批处理底是那里不对.
为了方便用户的浏览和版主的管理,请在帖子的标题中简要叙述其内容或意图
修改标题可点击帖子下方的"编辑"按钮,在编辑页面中修改标题后确认即可
若三日后仍未进行修改,将由版主进行修改,同时将扣除此帖作者的4点积分
—————————————— Edited by willsort ——————————————
Last edited by sglxy on 2005-11-1 at 23:51 ]
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 ]
|
|
2005-10-29 20:50 |
|
|
sglxy
中级用户
   MS-DOS爱好者
积分 397
发帖 87
注册 2002-12-15
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
各位版主,有在线的吗?麻烦你们给看看,先谢谢了。
Hello, moderators. Is anyone online? Please take a look for me. Thanks in advance.
|
|
2005-10-29 22:44 |
|
|
sglxy
中级用户
   MS-DOS爱好者
积分 397
发帖 87
注册 2002-12-15
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
可惜,高手们都不在!
What a pity, the experts are all not here!
|
|
2005-10-30 19:51 |
|
|
JonePeng
金牌会员
      D◎$ Fαп
积分 4562
发帖 1883
注册 2004-1-19 来自 广东广州
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
试试将 [%WHAT%] 改为 [%%WHAT%%]
Try to change to
|

----====≡≡≡≡ 我的至爱,永远是MSDOS!≡≡≡≡====----
|
|
2005-10-30 23:06 |
|
|
本是
银牌会员
    
积分 2221
发帖 789
注册 2005-1-27
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
Re sglxy:
你的what的使用方法有问题,不应该用what S,要用what C "提示信息" 字符列表,C命令会自动限制输入字符的范围,因而不用再进行IF测试,修改如下:
*******************************
set WHAT=
what C "你要恢复系统到哪一个分区(请输入分区号或盘符)?(123456789或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 ]
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 ]
|

my major is english----my love is dos----my teacher is the buddha----my friends--how about U |
|
2005-10-31 12:03 |
|
|
sglxy
中级用户
   MS-DOS爱好者
积分 397
发帖 87
注册 2002-12-15
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
谢谢"本是"兄弟的答复,但是我还有个问题,请看:
for %%a in (D E F G H I J K L) do goto _copy
如果这样改过后的语法是不是有点别扭?
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?
|
|
2005-10-31 12:56 |
|
|
willsort
元老会员
         Batchinger
积分 4432
发帖 1512
注册 2002-10-18
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
Re sglxy & 本是:
sglxy 兄原来的代码会产生问题,应该与 %what% 变量有关,至于 what s 的使用法对错,因为早已不接触这个工具而无法置评;不过我猜测 what s 是接受字符串输入的,因此也应该能实现你的意图才对。
for %%a in (D E F G H I J K L) do IF [%%a]==[%WHAT%] goto _copy 不仅仅“限制输入字符的范围”,同时将对输入的字符进行分选,为字母则 goto _copy ,为数字则 ghost ,因此不应省略其中的 if 片断。
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 == 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.
|

※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得! |
|
2005-10-31 14:16 |
|
|
本是
银牌会员
    
积分 2221
发帖 789
注册 2005-1-27
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
willsort说的“
for %%a in (D E F G H I J K L) do IF == goto _copy 不仅仅“限制输入字符的范围”,同时将对输入的字符进行分选,为字母则 goto _copy ,为数字则 ghost ,因此不应省略其中的 if 片断。”很正确。
what C 命令能对输入的字符进行范围限定,S命令不行。这对本.BAT应该是非常重要的。
此处的问题大概是NT系列操作系统对环境变量的设置规则不同于WIN9X所致!
Last edited by 本是 on 2005-10-31 at 16:38 ]
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 ]
|

my major is english----my love is dos----my teacher is the buddha----my friends--how about U |
|
2005-10-31 16:36 |
|
|
sglxy
中级用户
   MS-DOS爱好者
积分 397
发帖 87
注册 2002-12-15
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
非常感谢两位高手的指点,这个批处理是我制作的隐藏分区自动恢复功能的一段,方法是先:运行gdisk显示分区信息后,然后再手工输入要对哪一个分区进行操作。而what s命令将输入键值用%WHAT%变量传到for %%a in (D E F G H I J K L) do IF == goto _copy中进行判断,如果是其中的一个则说明该分区没有被隐藏(分区隐藏后不会有盘符),我就可以对该分区安装上一些个性化的恢复功能。但是就是这个我自认为万无一失的方法偏偏得不到应有的结果,我现在不明白的是,为何for %%a in (D E F G H I J K L) do IF == goto _copy这一句判断句会不起作用,我认为其语法应该没有错啊。
另外请教一下“ 本是”老兄,在需要限定输入字符范围的情况下“what c”命令该如何书写(语法)?得到的结果是什么样的变量形式,应该如何对该变量进行操作? 请您举个例子,谢谢!
Last edited by sglxy on 2005-10-31 at 18:38 ]
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 ]
|
|
2005-10-31 18:27 |
|
|
Archimonde
新手上路

积分 3
发帖 2
注册 2005-11-1
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
个人有个编程习惯,就是在出错语句的前面将它调用的参数一一显示一下,不知道你尝试过没有
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
|
|
2005-11-1 13:37 |
|
|
willsort
元老会员
         Batchinger
积分 4432
发帖 1512
注册 2002-10-18
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
Re sglxy:
what c 的用法 本是 兄在5楼就已给出了,最后一个参数 123456789DEFGHIJKL 即是限定其输入范围的,what 的其它用法多看其命令行帮助也应不难理解。
for %%a in (D E F G H I J K L) do IF [%%a]==[%WHAT%] goto _copy 是没有什么语法错误,但不保证没有用法错误,如果 %WHAT% 的变量值的前或后含有空格,那么你就永远无法使 if 的判断成立。所以应该根据 Archimonde 的建议,在for语句前加一句 echo what result=[%what%] 查看其输出结果是否正常。如果这个结果正常,那问题可能处在其它语句中。
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 == 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= 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.
|

※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得! |
|
2005-11-2 12:55 |
|