cmd,程序生成帮助文件

编程入门 行业动态 更新时间:2024-10-28 18:29:29
本文介绍了cmd,程序生成帮助文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 @echo off md helpgen 2>nul cd helpgen for /F %%i in ('help') do ( echo %%i|findstr /R "^[A-Z]*$" >nul if "%ERRORLEVEL%"=="0" ( help %%i>%%i.txt ) ) cd ..

应该从 help 命令为每个文件创建帮助文件。 但是...它不能正常工作,我不知道为什么。帮助我)

This program is supposed to make help-files for every file from the help command. But... it doesn't work correctly and i have no idea why. help me please)

推荐答案

您的代码不工作,因为%ERRORLEVEL%在解析时扩展,整个括号FOR块代码在一遍中解析。您希望每次迭代的值为ERRORLEVEL,但是您的代码在执行循环之前已经存在的值为ERRORLEVEL。

Your code is not working because %ERRORLEVEL% is expanded at parse time and the entire parenthesized FOR block of code is parsed in one pass. You want the value of ERRORLEVEL for each iteration, but your code is getting the value of ERRORLEVEL that existed before the loop is executed.

一个解决方案是启用延迟扩展顶部使用 setlocal enableDelayedExpansion 。然后在你的循环中使用!ERRORLEVEL!而不是%ERRORLEVEL%。

One solution is to enable delayed expansion at the top using setlocal enableDelayedExpansion. Then within your loop use !ERRORLEVEL! instead of %ERRORLEVEL%. The delayed expansion will give the desired value of ERRORLEVEL at execution time of each iteration.

键入帮助设置或 set /?从命令行获取有关延迟扩展的更多信息。

Type help set or set /? from the command line to get more information about delayed expansion.

但是有一个更容易的解决方案,变量扩展一起。 command1&&& command2 将仅在command1成功时执行command2。如果前面的命令不成功,还有 || 运算符用于执行命令。

But there is an easier solution that avoids variable expansion all-together. command1 && command2 will execute command2 only if command1 was successful. There is also the || operator to use to execute a command if the prior command was not successful.

但是整个练习是无意义的,因为你的FINDSTR表达式不会给出正确的结果,所以你的最终输出仍然是错误的。

But the whole excercise is kind of pointless because your FINDSTR expression will not give the correct results, so your final output will still be wrong.

Ansgar Wiechers确定了一个搜索模式他的回答。不需要tokens = 1,因为这是默认设置。

Ansgar Wiechers identified a search pattern that works in his answer. The "tokens=1" is not needed because that is the default setting.

最终脚本可以简单:

@echo off md helpgen 2>nul cd helpgen for /f %%i in ('help ^| findstr /rc:"^[A-Z][A-Z]* "') do help %%i>%%i.txt

更多推荐

cmd,程序生成帮助文件

本文发布于:2023-11-06 04:27:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1562718.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:帮助文件   程序   cmd

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!